Ale*_*lex 2 google-apps-script
我希望在通过 HTMLService 显示 Web 应用程序的同时,在 Apps Scripts 中获取当前浏览器窗口的完整 URL
当我尝试这个时,它不起作用,因为 Apps Scripts 是沙盒的,我得到了某种类型的另一个服务器 url
window.location.href
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我只能获取哈希或参数,而不是完整的 url
google.script.url.getLocation(function(location) {
console.log(location.parameters);
console.log(location.hash);
});
Run Code Online (Sandbox Code Playgroud)
来源:https : //developers.google.com/apps-script/guides/html/reference/url#methods
上述目的:我想要一个人们在已发布的 Web 应用程序中单击以删除浏览器工具栏的按钮。但是,浏览器工具栏在当前浏览器窗口中是不可移动的。因此,我想获取 Web App URL 并将其作为当前 Web 应用程序的新窗口放入 window.open() 中,因为可以通过这种方式删除浏览器工具栏。但我似乎无法获得当前的 URL。
我有什么想法可以实现这一目标吗?
提前致谢!
我也不知道您所说的开发人员模式是什么意思,但我猜测这是问题的答案。如果没有,请告诉我,我将删除它。
在客户端,您可以使用 Javascript:
<script>
function getUrl(){
google.script.run
.withSuccessHandler(function(url){
document.getElementById('mydiv').innerHTML='<p>' + url + '</p>';
})
.getScriptUrl()
</script>
<body>
<div id="mydiv"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
在谷歌脚本中:
function getScriptURL() {
return ScriptApp.getService().getUrl();
}
Run Code Online (Sandbox Code Playgroud)
2021 年 1 月 10 日:在 window.onload 中测试了上述代码,它使用企业帐户、V8 运行时和新编辑器返回正确的 url。
| 归档时间: |
|
| 查看次数: |
3294 次 |
| 最近记录: |