Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

javascript - Google apps script location.reload in web app

I am using a GAS web app that needs to refresh its contents when a user takes certain actions (like clicking on a particular div).

On the clientside, I have this script that gets 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 "Reloading..." so I know the callback gets called,but then it never reloads the page. Does Caja or google apps script disable page refreshing? Is there another way to refresh the page?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...