Automatically Redirecting to a Page

后端 未结 2 1723
忘掉有多难
忘掉有多难 2020-12-05 20:14

Inside a button click handler, I\'m creating a new web page like so:

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


        
相关标签:
2条回答
  • 2020-12-05 20:54

    Corey G's answer worked for me, but the problem is that the web page that I was redirecting was embedded into an iframe in the response of the GAS, so the real URL in the web browser was the script's one.

    This is what actually worked for me:

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

    This similar Q/A helped me to solve it.

    Hope it helps.

    0 讨论(0)
  • 2020-12-05 20:55

    This cannot be done in UiApp but it's doable in HtmlService:

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

    This should be easier; please file a feature request in the issue tracker and we will see how we can make this more pleasant.

    (Edit: To be clear, there's no way to do this from a UiApp callback; your entire app would have to be using HtmlService for this to work.)

    0 讨论(0)
提交回复
热议问题