Google apps script location.reload in web app

无人久伴 提交于 2019-11-30 14:55:43

All you need to do is use:

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

My original answer below works, but is un-needed:

There is a programmatic "Work Around" to reload/refresh the page in an Apps Script Web App. It is based on the capability of an html link tag to reload the page, and the ability of JavaScript to invoke the click event on that tag. You can hide the link if you want.

  • Add a link tag to your HTML
  • Hide the link tag if you wish
  • Add client side code in a script tag to invoke the 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 App - Apps Script

Eric Koleda

EDIT

Caja was removed July 16, 2016 from Web App HtmlService.

Native Sandbox Mode

An Update to HTML Service

End of edit

Unfortunately the Caja sanitization engine used by HtmlService restricts access to the window object, preventing you from programatically reloading the page. This is a known restriction of the service and we are working to better document it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!