Search code examples
google-apps-scriptgoogle-sites

Automatically Redirecting to a Page


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

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

and I want to redirect the user automatically to that page.

I wasn't able to find much information, can this be done?


Solution

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