【问题标题】:How To Create A Message Box From Google App Script To Web App如何创建从 Google App 脚本到 Web App 的消息框
【发布时间】:2020-07-07 09:35:26
【问题描述】:

我正在尝试创建一个从我的 .gs 到我的网络应用程序的消息框,我尝试了这些但消息框无法显示:

var html = HtmlService.createHtmlOutputFromFile('View');
SpreadsheetApp.getUi().showModalDialog(html, 'Dialog title');

Browser.msgBox('Hello!', Browser.Buttons.OK);

HtmlService.createHtmlOutput("Hello!");

这些方法是正确的方法吗?您的回复将不胜感激:)

【问题讨论】:

  • 当你说网页时,你的意思是你试图在 WebApp 中嵌入这段代码吗?如果可能,请提供更多上下文/代码。
  • 哦,对不起,我的意思是 Web 应用程序
  • 这个网络应用在哪里?
  • @TheMaster 我只是想从我的 .gs 创建一个消息框,我还应该发布我的 html 代码吗?
  • @Ray 上下文。退后。函数是怎么调用的?从哪里来?

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


【解决方案1】:

您尝试使用的方法是为use in the context of a Google Spreadsheet 设计的

  • 您不能在 WebApp 中使用它们,即使您的 WebApp 已绑定到电子表格。
  • 无论如何,这没什么意义,因为当您部署 WebApp 时,您与 WebApp 界面进行交互,而不是与电子表格 UI。
  • 您需要使用可从 WebApp 客户端访问的 Javascript 方法,请参阅 here

示例:

代码.js

function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}


function called(){
  
  Logger.log("I was called");
  //the rest of your code
}

index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <script>
    if (confirm("Please confirm, are you sure you want to continue?")) {
     alert( "google.script.run will be called");
     google.script.run.called();
   } else {
    alert( "You cancelled!");
   } 
    </script>
  </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 2019-10-28
    • 1970-01-01
    相关资源
    最近更新 更多