Home > Blockchain >  How to Refresh the Google WebApp on every update?
How to Refresh the Google WebApp on every update?

Time:02-24

I'm getting the data from Google sheets and displaying it on Google WebApp front end. But The problem is, the Google WebApp front end don't update itself unless the window is refreshed.

Is there a way to refresh itself when it detects a data change in Google sheets or refreshes itself every 15 minutes.

index.html

<script>
function onSuccess(UpdatedData) {
var div = document.getElementById('output');

div.innerHTML = '<div  style="width: 6rem; ">Last Updated:</div> <span >'  UpdatedData   '</span>';
}

google.script.run.withSuccessHandler(onSuccess).getdata();
</script>

<body>
<div id="output"></div>
</body>

CodePudding user response:

If you want a function to execute every X seconds, you can use the setInterval method.

For example, in your script:

<script>
   function onSuccess(UpdatedData) {
     var div = document.getElementById('output');
   
     div.innerHTML = '<div  style="width: 6rem; ">Last       Updated:</div> <span >'  UpdatedData   '</span>';
     }
     setInterval(()=>{
       google.script.run.withSuccessHandler(onSuccess).getdata()
     },1e4)
     
</script>
<body>
   <div id="output"></div>
</body>

This will make the function inside the setInerval run every 10 second (10 seconds == 1e4, the time should be in milliseconds). So for refreshing it every 15 minuts you should use 9e5

  • Related