首页 > 解决方案 > Refresh Client Side Web Page

问题描述

I created a google web app that gets information from a google spreadsheet. If I have the web app opened in a browser, then go make a change in the spreadsheet, within the webpage, can I display some text that the page needs to be refreshed?

标签: google-apps-script

解决方案


一个简单的轮询示例:

只需复制代码并运行开始轮询。单击开始轮询按钮。更改活动工作表的 A1 中的值并观察侧边栏。

function startPolling() {
  var html='<div id="msg"></div><input type="button" value="Start Polling" onClick="startPolling();" />';
  html+='<script>function startPolling(){setInterval(getA1,5000);}function getA1(){google.script.run.withSuccessHandler(function(hl){document.getElementById(\'msg\').innerHTML=hl;}).getA1();}</script>';
  var userInterface=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showSidebar(userInterface); 
}

function getA1() {
  //SpreadsheetApp.getActive().toast('Polling');//helpful for debugging
  return SpreadsheetApp.getActiveSheet().getRange('A1').getValue();
}

推荐阅读