Skip to content Skip to sidebar Skip to footer

Google Appscript WebApp Refresh

Does anyone know of an effective way of triggering a window refresh for a deployed Google Appscript Web Application using Javascript? I've searched and tested variations of window.

Solution 1:

In order to refresh the Web App, you can just use Window.open(url, windowName), like this:

window.open("https://script.google.com/macros/s/{your-webapp-id}/exec", "_top");

Update:

You could also retrieve the script URL via ScriptApp.getService().getUrl(), instead of writing it yourself. To do that, you would have to retrieve this information from the server-side (you cannot access classes like ScriptApp from the client-side). You have to use google.script.run to execute server-side functions from the client-side:

function retrieveUrl() {
  google.script.run.withSuccessHandler(refresh).getUrl();
}

This way, retrieveUrl will execute a function called getUrl from your server code (.gs), which could be something like this:

function getUrl() {
  return ScriptApp.getService().getUrl();
}

Finally, when getUrl returns successfully, the success handler will execute a client-side function called refresh (and its return value –the script URL– will be passed as a parameter):

function refresh(scriptUrl) {
  window.open(scriptUrl, "_top");
}

Reference:


Post a Comment for "Google Appscript WebApp Refresh"