Google Apps Script redirect in google Sites gadget

2019-03-01 17:36发布

问题:

I'm building a web application in google sites. Currently I have two forms in google script, the first one load a Spreadsheet and display 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();
}

回答1:

I solved it adding:

<base target="_top">

to the html code and changing the javascript redirect:

window.top.location.href = url;