javascriptgoogle-apps-scriptreloadgoogle-sites-2016

Reload a GAS's web app embedded on google sites


I have a webapp embedded in a new google site. This app embedded necessarily must reload the web app. When the web app's form is completed, the app open a modal with a button that call this function:

function reloadPage(){
google.script.run
.withSuccessHandler(function(url){window.open(url,"_top");})
.getScriptURL();
}

And this server side function:

function getScriptURL() {

var url = ScriptApp.getService().getUrl();
console.log(url)
return url ;
}

My console register this error:

Unsafe Javascript attempt to initiate navigation usserCodeAppPanel:150 for frame with origin “https://sites.google.com” from frame with URL”URL”. The frame attempting navigation of the top-level window is sandboxed, but the flag of ‘ allow-top-navigation' or ‘allow-top-navigation-by-user-activation’ is not set.

I need to do a reload because the form registers a value in a sheet. My app verifies that the value I will enter is not repeated on the sheet. So after submitting the form, the value just registered is not reflected. For example, I enter the ID 1, the validator looks for that value in the worksheet. If it does not find it, it allows you to enter it, otherwise it sends an alert. After submitting the form the fields are cleared, I re-enter ID 1 then the validator lets it pass because it verifies that 1 is not on the spreadsheet. So with a recharge this problem does not happen.

There's a way to reload the app without this error? Greetings!


Solution

  • I found a solution:

    1. First on my html header put the next line:

    <base target="self">

    1. I change my javascript function to this:

      function reloadPage(){google.script.run.withSuccessHandler(function(url){window.open(url,"_self");}).getScriptURL();}
      
    2. In my doGet function i put this:

      function doGet(e){
      var output = HtmlService.createTemplateFromFile('index');
      return  output.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
       }
      

    With all this changes i get solved my problem. Thanks for the comments! Greetings!