我正在使用一个 GAS Web 应用程序,当用户执行某些操作(例如单击特定的 div)时,该应用程序需要刷新其内容。
在客户端,我有一个从 onclick 调用的脚本
google.script.run.withSuccessHandler(refreshCallback).myServersideFunction();
function refreshCallback(roomsPlus) {
var statusDiv = document.getElementById("status");
statusDiv.innerHTML = "Reloading...";
window.location.reload(true);
};
状态 div 更改为“正在重新加载...”,因此我知道回调被调用,但它永远不会重新加载页面。 Caja 或 google apps 脚本是否禁用页面刷新?还有其他方法刷新页面吗?
您需要做的就是使用:
window.open("https://script.google.com/macros/s/web_app_ID/dev",'_top');
我原来的答案如下有效,但不需要:
有一个编程“解决方法”可以重新加载/刷新 Apps 脚本 Web 应用程序中的页面。它基于 html 链接标记重新加载页面的能力,以及 JavaScript 调用该标记上的单击事件的能力。如果需要,您可以隐藏该链接。
- 将链接标签添加到您的 HTML 中
- 如果您愿意,可以隐藏链接标签
- 在脚本标记中添加客户端代码以调用链接标记上的单击事件
- 按照您想要的方式运行代码
测试按钮:
<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>
最好实现一个简单的页面导航系统:
页面导航 Web 应用程序 - Apps 脚本 https://script.google.com/d/1WArwQ_wtkwSjom9hmmxfClFX3lKa5LrFOPSrdndeIETJMRple_lDbF0L/edit?usp=sharing
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)