如何阻止重定向 URL 被屏蔽?

How to stop redirected URL from being masked?

我的 google 应用程序脚本(附加到 google 文档)中有一个 doGet 函数,它作为网络应用程序发布,我希望用户被重定向到另一个网页。重要的是,我希望他们被重定向的页面的 URL 显示在地址栏中,并且他们被重定向的页面的标题是选项卡的标题(在 Chrome 中)。

我试过使用元刷新标签,并设置 window.location.href。这两个重定向都正确,但它们在地址栏中显示地址应用程序的 URL,而不是用户重定向到的页面的 URL。

以下附在 Google 文档中的脚本说明了这个问题。

function doGet(request) {
  var drive = DriveApp;
  var docs = DocumentApp;
  var Id = docs.getActiveDocument().getId();
  var document = docs.openById(drive.getFileById(Id).makeCopy().getId());
  document.setName("Test doc 2");
  var URL = document.getUrl();
  return HtmlService.createHtmlOutput('<meta http-equiv="refresh" content="0; url=' + URL + '" />')
}

将脚本发布为 Web 应用程序,然后访问 URL 会将您重定向到新创建的文档,但地址栏中显示的是脚本的 URL。

查看此 Google 文档以获取示例:https://docs.google.com/document/d/1HpBkNGGGjKj3W6QXThtGdniSO_UTANo8LcqmgZowdTQ/edit

由于您的 html 是 ,您应该使用

window.top.location = url

加载到顶部框架。