Can't stop Google Apps Script from masking redirected URL

与世无争的帅哥 提交于 2019-12-31 05:57:09

问题


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).

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.

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 + '" />')
}

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.

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


回答1:


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

window.top.location = url

to load in the top frame.



来源:https://stackoverflow.com/questions/56685553/cant-stop-google-apps-script-from-masking-redirected-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!