【问题标题】:How can I make this work run from the Client Side我怎样才能使这项工作从客户端运行
【发布时间】:2020-09-19 18:02:20
【问题描述】:

我已经用尽了所有可能尝试的排列方式,例如将所有 .js 代码移动到 html 中,但函数不会从文档侧边栏运行,在每次运行时 - 单击这些按钮中的任何一个 - 我有返回脚本的编辑器以运行侧边栏。我嵌入到我的 html 中的函数的脚本是:

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>

【问题讨论】:

标签: javascript google-apps-script web-applications


【解决方案1】:
  1. onclick="javascript:Check();"onclick="javascript:Clear();" 中删除javascript:,因为它不需要。如果您使用事件侦听器而不是内联 JavaScript,效果会更好。
  2. 使用google.script.run 时,请使用withSuccessHandlerwithFailureHandler
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();
}

  1. 查看脚本执行页面,可能记录了服务器端错误。

  2. 尝试禁用新的运行时(Chrome V8)

资源

相关

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-02
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    相关资源
    最近更新 更多