简体   繁体   English

如何获取截至 2021 年 7 月的谷歌应用脚​​本网站的 URL

[英]how to get URL of google app script web as of July 2021

In my Google Application Script Web application I need to get the URL so I can reload the page.在我的 Google Application Script Web 应用程序中,我需要获取 URL 以便我可以重新加载页面。 I need to distinguish whether the end user is using DEV or EXEC environments.我需要区分最终用户是使用 DEV 还是 EXEC 环境。

Server side approach服务器端方法

With my current settings使用我当前的设置

  • using gmail.com account使用 gmail.com 帐户
  • Enable Chrome V8 runtime is checked启用 Chrome V8 运行时被选中

is the ScriptApp.getService().getUrl() ALWAYS returning EXEC url, never the url of DEV.ScriptApp.getService().getUrl()总是返回 EXEC url,而不是 DEV 的 url。

I read about Tanaike's workaround but he said that when V8 runtime is disabled, it returns the exec URL .我读过 Tanaike 的解决方法,但他说when V8 runtime is disabled, it returns the exec URL It works the opposite for me and more importantly I have not idea how to use his suggestion "Method: projects.deployments.list".它对我来说正好相反,更重要的是我不知道如何使用他的建议“方法:projects.deployments.list”。 I am using just script.google.com with my gmail account.我的 gmail 帐户仅使用 script.google.com。

Browser side approach浏览器端方法

If I want to get the URL on the browser side using console.log(top.location.pathname) I get issue with the cross-origin.如果我想使用console.log(top.location.pathname)在浏览器端获取 URL,我会遇到跨域问题。

Uncaught DOMException: Permission denied to access property "pathname" on cross-origin object

although I am able to see the URL from browser console虽然我可以从浏览器控制台看到 URL

在此处输入图片说明

So my question is whether there is a way or workaround how I can get URL of my GAS web?所以我的问题是是否有办法或解决方法如何获取我的 GAS 网站的 URL?

This issue has been reported in Google's Issue Tracker here: https://issuetracker.google.com/193820645此问题已在此处的 Google 问题跟踪器中报告: https : //issuetracker.google.com/193820645

Click the "star" next to the issue number to indicate you are affected by ti too.单击问题编号旁边的“星号”表示您也受 ti 影响。


Both URLs have the same Id, you can just build the URL with the trailing part you need.两个 URL 具有相同的 Id,您可以使用所需的尾随部分构建 URL。

var url = ScriptApp.getService().getUrl();
console.log(url);
url = url.split('/').splice(0,6).join('/');
console.log(url)
var execVersion = "/exec";
var devVersion = "/dev";
console.log("exec: "+url+execVersion)
console.log("dev: "+url+devVersion)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM