自动重定向到页面

问题描述 投票:10回答:2

在按钮单击处理程序中,我正在创建一个新的网页,如下所示:

var page = SitesApp.getPageByUrl(url).createPageFromTemplate(title, name, template);

我想将用户自动重定向到该页面。

我无法找到太多信息,可以这样做吗?

google-apps-script google-sites
2个回答
10
投票

这不能在UiApp中完成,但它在HtmlService中是可行的:

function doGet() {
  return HtmlService.createHtmlOutput(
    "<form action='http://www.google.com' method='get' id='foo'></form>" + 
    "<script>document.getElementById('foo').submit();</script>");
}

这应该更容易;请在issue tracker提交功能请求,我们将看到如何使这更加愉快。

(编辑:要清楚,没有办法从UiApp回调中执行此操作;您的整个应用程序必须使用HtmlService才能实现此功能。)


9
投票

Corey G的答案对我有用,但问题是我重定向的网页在GAS的响应中被嵌入到iframe中,因此Web浏览器中的真实URL是脚本的。

这实际上对我有用:

function doGet() {
  return HtmlService.createHtmlOutput(
    "<script>window.top.location.href='https://example.com';</script>"
  );
}

This similar Q/A帮助我解决了这个问题。

希望能帮助到你。

© www.soinside.com 2019 - 2024. All rights reserved.