无法阻止Google Apps脚本屏蔽重定向的URL [英] Can't stop Google Apps Script from masking redirected URL

本文介绍了无法阻止Google Apps脚本屏蔽重定向的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a doGet function in my google apps script (attached to a google doc) which is published as a web app and I want the user to be redirected to another web page. Importantly, I want the URL of the page they are redirected to to be displayed in the address bar, and the title of the page they are redirected to to be the title of the tab (in Chrome).

我尝试使用元刷新标签,还设置了window.location.href.两者都可以正确重定向,但是它们会在地址栏中显示地址应用程序的URL,而不是用户重定向到的页面的URL.

I've tried using a meta refresh tag, and also setting the window.location.href. Both of these redirect correctly but they show the URL of the address app in the address bar, not the URL of the page the user is redirected to.

以下附加到Google文档的脚本说明了此问题.

The below script, attached to a Google Doc, illustrates the problem.

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.

Publishing the script as a web app and then visiting the URL redirects you to the newly created document, but it is the URL of the script that displays in the address bar.

有关示例,请参见此Google文档: https://docs.google.com/document/d/1HpBkNGGGjKj3W6QXThtGdniSO_UTANo8LcqmgZowdTQ/edit

See this Google Doc for an example: https://docs.google.com/document/d/1HpBkNGGGjKj3W6QXThtGdniSO_UTANo8LcqmgZowdTQ/edit

推荐答案

由于您的html已加载到iframe中,因此您应该使用

Since your html is loaded in a iframe, You should use

window.top.location = url

加载到顶部框架中.

这篇关于无法阻止Google Apps脚本屏蔽重定向的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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