gpt4 book ai didi

javascript - GAS 将后端脚本与页面加载同步

转载 作者:行者123 更新时间:2023-12-01 00:29:09 25 4
gpt4 key购买 nike

在我的 html 代码中,我调用一个脚本来编辑 Google 表单,然后加载该表单。我的问题是,网页在脚本更新完成之前加载。

<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<script>
google.script.run.changeForm();
window.top.location.href='https://docs.google.com/forms/d/e/ABCDpQLSdV2e61UFkG-_LcVBRpWe9F1MizNJ-P5JUCUGRlWiFSoImPkA/viewform';
</script>
<body>
</body>
</html>

我的临时解决方法是 setTimeout(),但这感觉像是一个肮脏的小把戏。

<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<script>
google.script.run.changeForm();
setTimeout(function(){
window.top.location.href='https://docs.google.com/forms/d/e/ABCDpQLSdV2e61UFkG-_LcVBRpWe9F1MizNJ-P5JUCUGRlWiFSoImPkA/viewform';
}, 2000);
</script>
<body>
</body>
</html>

有没有更好的方法来解决这个问题?

最佳答案

你应该尝试

google.script.run.withSuccessHandler(success).changeForm();
function success(){
window.top.location.href='https://docs.google.com/forms/d/e/ABCDpQLSdV2e61UFkG-_LcVBRpWe9F1MizNJ-P5JUCUGRlWiFSoImPkA/viewform';
}

withSuccessHandler(success) 在函数 changeForm() 完成执行后运行参数中的函数

关于javascript - GAS 将后端脚本与页面加载同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58717533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com