Google apps location.reload script in web app

I am using a GAS web application that should update its contents when a user takes certain actions (for example, clicking on a specific div).

On the client computer, I have this script that is called from onclick

google.script.run.withSuccessHandler(refreshCallback).myServersideFunction(); function refreshCallback(roomsPlus) { var statusDiv = document.getElementById("status"); statusDiv.innerHTML = "Reloading..."; window.location.reload(true); }; 

The status div changes to "Reload ...", so I know that the callback call is called, but then it never reloads the page. Caja or google apps script disable page refresh? Is there any way to refresh the page?

+4
source share
2 answers

EDIT

Caja was removed on July 16, 2016 from the HtmlService web application.

Sandbox native mode

HTML Service Update

End of editing

Unfortunately, the Caja sugar refining mechanism used by the HtmlService restricts access to the window object, which prevents the page from reloading programmatically. This is a known limitation of the service, and we are working to better document it.

+2
source

All you have to do is use:

 window.open("https://script.google.com/macros/s/web_app_ID/dev",'_top'); 

My original answer below works, but not needed:

There is a software "Work Around" for reloading / updating a page in the Script application. It is based on the ability of the html link tag to reload the page and the ability of JavaScript to trigger a click event on this tag. You can hide the link if you want.

  • Add link tag to your HTML
  • Hide link tag if you want
  • Add client-side code in the Script tag to trigger a click event on the link tag
  • Run the code however you want

Test Button:

 <button onmouseup="reloadTheWebApp()">Trigger the Link Tag</button> 

Link

 <a id="testLink" style="display:none" href="https://script.google.com/macros/s/script_ID/exec">Reload the Web App</a> 

Script:

 <script> window.reloadTheWebApp = function() { console.log('reloadTheWebApp ran'); var linkTag = document.getElementById('testLink'); linkTag.click(); } </script> 

It may be preferable to implement a simple page navigation system:

Page Navigation Web Application - Script Applications

0
source

All Articles