使用 google.script.run 在 Google App Script 中运行服务器端函数



下面是我在Google App Script中的HTML文件。

它在电子表格上创建一个对话框。按下 ok 按钮时,我希望它运行我在 App 脚本中创建的函数并关闭对话框。

当我单击"确定"时,应用程序脚本代码未运行。我能做得更好吗?

谢谢。

<!DOCTYPE html>
<html>
<head>
<h3>Welcome</h3>
<meta charset="utf-8">
<title>SEOMango</title>
<script src="http://code.jquery.com/jquery.min.js"></script>

</head>
<body>
<input type="button" value="Ok" class="create ok_button" 
onclick="close1();" id="ok_button"/>

<!--JQUERY-->
<script 
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">  
</script>
<script>
function close1()
{
google.script.host.close();
google.script.run.withSuccessHandler.doSomething();
}
</script>
</body>
</html>

尝试这样的事情:

function close1()
{
google.script.run.withSuccessHandler(end).doSomething();
}
function end()
{
google.script.host.close();
}

您首先需要在谷歌端执行您的函数doSomething然后如果成功调用end()函数,其中包含google.script.host.close()以关闭侧边栏/对话框。

正如@tehhowch提到的,您在执行函数doSomething()之前在此处关闭 Html 页面。

最新更新