我从Google中获取数据,并将其显示在Google WebApp前端。但问题是,谷歌WebApp前端不更新自己,除非窗口被刷新。
当它检测到Google中的数据更改或每15分钟刷新一次时,是否有一种方法来刷新自己?
index.html
<script>
function onSuccess(UpdatedData) {
var div = document.getElementById('output');
div.innerHTML = '<div class="badge bg-primary text-wrap fw-normal" style="width: 6rem; ">Last Updated:</div> <span class="font-weight-normal text-muted fs-6">'+ UpdatedData + '</span>';
}
google.script.run.withSuccessHandler(onSuccess).getdata();
</script>
<body>
<div id="output"></div>
</body>发布于 2022-02-23 08:55:02
如果希望每X秒执行一次函数,则可以使用setInterval方法。
例如,在您的脚本中:
<script>
function onSuccess(UpdatedData) {
var div = document.getElementById('output');
div.innerHTML = '<div class="badge bg-primary text-wrap fw-normal" style="width: 6rem; ">Last Updated:</div> <span class="font-weight-normal text-muted fs-6">'+ UpdatedData + '</span>';
}
setInterval(()=>{
google.script.run.withSuccessHandler(onSuccess).getdata()
},1e4)
</script>
<body>
<div id="output"></div>
</body>这将使setInerval内部的函数每10秒运行一次(10秒== 1e4,时间以毫秒为单位)。因此,每15分钟刷新一次,您应该使用9e5
https://stackoverflow.com/questions/71222533
复制相似问题