我如何使这项工作从客户端运行 [英] How can I make this work run from the Client Side
本文介绍了我如何使这项工作从客户端运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尽力尝试了所有可能的排列方式,例如将所有.js代码移到html中,但是在每次运行时都无法从doc侧边栏运行这些功能-单击这些按钮中的任何一个-我已经返回到脚本的编辑器以运行侧栏.我嵌入到html中的函数的脚本是:
I have exhausted all possible permutations I could possibly try, like moving all of the .js code into the html, but the functions would not run from the doc' sidebar, in every run -click any of those buttons- I have to go back to the script's editor to run the sidebar. The script for functions I embedded in my html is:
function Check() {
google.script.run.results_run();
}
function Clear() {
google.script.run.results_clear();
}
<button type="button" class="c-btn c-btn--primary" onclick="javascript:Check();"> Check </button>
<a class="clear-highlights" onclick="javascript:Clear();">Clear highlights</a>
推荐答案
- 从
onclick="javascript:Check();"
和onclick="javascript:Clear();"
中删除javascript:
,因为不需要.如果您使用事件监听器而不是内联JavaScript,那就更好了. - 使用
google.script.run
时,请使用withSuccessHandler
和withFailureHandler
.
- Remove
javascript:
fromonclick="javascript:Check();"
and fromonclick="javascript:Clear();"
as it's not needed. Better if you use an event listener instead of inline JavaScript. - When using
google.script.run
usewithSuccessHandler
andwithFailureHandler
.
function Check() {
google.script.run
.withSuccessHandler(function(){
// if needed do something when the server side function runs succesfully
})
.withFailureHandler(function(error){
// if an error occurss on server side log the error into the console
console.error(error.message,error.stack);
}).results_run();
}
function Clear() {
google.script.run
.withSuccessHandler(function(){
// if needed do something when the server side function runs succesfully
})
.withFailureHandler(function(error){
// if an error occurss on server side log the error into the console
console.error(error.message,error.stack);
}).results_clear();
}
-
查看脚本执行页面,可能会记录服务器端错误.
Review the script execution page, there might be logged a server-side error.
尝试禁用新的运行时(Chrome V8)
Try disabling the new runtime (Chrome V8)
资源
相关
- How can I make this work run from the Client Side
- google.script.run not working on Chrome Browser for some users
这篇关于我如何使这项工作从客户端运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文