在Apps脚本中获取完整的浏览器URL [英] Get the full browser URL in Apps Script

查看:124
本文介绍了在Apps脚本中获取完整的浏览器URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在通过HTMLService显示Web应用程序时在Apps脚本中获取当前浏览器窗口的完整URL.

I'm looking to get the full URL of the current browser window in Apps Scripts while displaying the web app via HTMLService

  1. 当我尝试此操作时,它不起作用,因为Apps脚本已被沙箱化,并且我得到了另一个某种形式的服务器URL

  1. When I try this, it doesn't work because the Apps Scripts is sandboxed and I get another server url of some sort

window.location.href 


尝试此操作时,我只能获取哈希或参数,而不能获取完整的网址

When I try this, I can only fetch the hash or parameters, not the full url

google.script.url.getLocation(function(location) {
  console.log(location.parameters);
  console.log(location.hash);
});

来源: https://developers.google.com /apps-script/guides/html/reference/url#methods


上述目的: 我希望人们在已发布的Web应用程序中单击一个按钮以删除浏览器工具栏.但是,浏览器工具栏在当前浏览器窗口中不可移动.因此,我想获取Web应用程序URL并将其作为当前Web应用程序的新窗口放入window.open()中,因为可以通过这种方式删除浏览器工具栏.但是我似乎无法获取当前网址.


Purpose for the above: I want a button that people click on in the published Web App to remove the browser toolbar. However, the browser toolbar is not removable in the current browser window. So I want to fetch the Web App URL and put it in window.open() as a new window with the current web app because the browser toolbar can be remove this way. But I can't seem to get the current URL.

有什么想法可以实现这一目标吗?

Any ideas how I can achieve this?

提前谢谢!

推荐答案

我也不知道您所说的开发人员模式是什么意思,但我猜测这是问题的答案.如果没有,请告诉我,我将其删除.

I don't know what you meant by developer mode either but I took a guess at this being the answer to the question. If not, let me know and I'll remove it.

在客户端,您可以使用Javascript:

On the clientside you can use 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>

在Google脚本中:

In Google Script:

function getScriptURL() {
  return ScriptApp.getService().getUrl();
}

这篇关于在Apps脚本中获取完整的浏览器URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆