How to redirect to another webpage from Google Apps Script Gadget?
Asked Answered
M

1

2

I'm building a web application in Google Sites. Currently, I have two forms, the first one loads a Spreadsheet and displays it as a table, then when you select a row from the table, the script calls another Web App with a GET request and with a few parameters (as ?rowIndex=X&columnIndex=..).

This is working fine if I deploy the first form as a Web App. But if I insert the first script as a "Google Apps Script Gadget" in my Google Sites webpage it seems that is embedded as an Iframe that cannot redirect to other webpages/scripts (it just shows a blank iframe).

Is there any way to solve this without merging both scripts in one?

For the redirect, I'm using javascript in the HTML form.

windows.location="secondScriptUrl"+"?parameters..." 

and the second script just generates the HTML from the doGet function

function doGet(e) {
   return HtmlService.createTemplateFromFile('index').evaluate();
}
Massengale answered 17/2, 2016 at 10:28 Comment(4)
why are 2 web apps being used out of curiosity?Itinerancy
Because one is used to show information stored in a Spreadsheet and when you select one row of data, the data is sent to the other Web App that let you edit and manage the information.Massengale
HtmlService doesn't allow to acces different html files in the same project, you have to make a GET request again and I tought that It was better to have separate projects.Massengale
right, it's a single-page app but you can certainly store the the needed html for other page views client side or write the change logic in JS. Running a google.script.run.yourFunctionToGetHtmlContent(). is going to be faster than a whole browser window refresh too. That .top was a missing piece for me on redirects though.Itinerancy
M
2

I solved it adding:

<base target="_top">

to the html code and changing the javascript redirect:

window.top.location.href = url; 
Massengale answered 17/2, 2016 at 12:36 Comment(1)
From today, I noticed that it is not working anymore.Saylor

© 2022 - 2024 — McMap. All rights reserved.