javascript 部署网络应用程序时如何在 Google 应用程序脚本中创建警报消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26339105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create an alert message in Google app script while deploying a web app?
提问by Yair Saban
I am trying to create a web app using Google app script, that if you press a button, you may get an alert message.
我正在尝试使用 Google 应用程序脚本创建一个网络应用程序,如果您按下按钮,您可能会收到一条警报消息。
In the home.gs file I tried this :
在 home.gs 文件中我试过这个:
function let_user_decide()
{
Browser.msgBox('Greetings', 'Press Yes or No?', Browser.Buttons.YES_NO);
};
unfortunately I keep getting this when I press the button when I should get the alert message :
不幸的是,当我应该收到警报消息时按下按钮时,我不断收到此消息:
Exception: Cannot call Browser.inputBox() from this context.
例外:无法从此上下文调用 Browser.inputBox()。
Important to mention : my script is using Google spreadsheet but the msgBox should appear in the webapp! In addition, I use HTML
重要的是:我的脚本正在使用 Google 电子表格,但 msgBox 应该出现在 web 应用程序中!另外,我使用HTML
Any idea what am I doing wrong? And how can I fix it?
知道我做错了什么吗?我该如何解决?
采纳答案by Serge insas
Browser.msgBox is indeed only available in the spreadsheet interface, not in webapps.
Browser.msgBox 确实只在电子表格界面中可用,在 webapps 中不可用。
You have a lot of alternatives to throw alerts but you should mention wether you use UiApp or HTML Service.
您有很多方法可以发出警报,但您应该提及是使用 UiApp 还是 HTML 服务。
In UiApp you can create a popupPanelfor example while in HTML you can throw alerts (throw new Error('sample alert')) or use JQuery Ui elements to do that.
例如,在 UiApp 中,您可以创建一个popupPanel,而在 HTML 中,您可以抛出警报(throw new Error('sample alert'))或使用 JQuery Ui 元素来执行此操作。