Reputation: 31
I have a little problem with Google Apps Script web app. The following script sample works perfectly in web app once its inside docs. But as a stand alone app in a browser, I keep having error messages. Please how can I make the "Browser.msgBox (prompt)" work in a browser?
In case you'd like to see the error message, the app can be accessed here.
// Script-as-app template.
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton('Click Me');
app.add(button);
var label = app.createLabel('The button was clicked.')
.setId('statusLabel')
.setVisible(false);
app.add(label);
var handler = app.createServerHandler('myClickHandler');
handler.addCallbackElement(label);
button.addClickHandler(handler);
return app;
}
function myClickHandler(e) {
var app = UiApp.getActiveApplication();
var label = app.getElementById('statusLabel');
label.setVisible(true);
Browser.msgBox("hello world");//THIS IS MY PROBLEM!!!
app.close();
return app;
}
Upvotes: 0
Views: 4947
Reputation: 1023
Browser.msgBox(prompt)
will only work if the app is being shown as a dialog, such as in a Google Spreadsheet. It isn't possible to suspend the script execution in a standalone webapp.
app.close()
isn't functional as well - you just can't close a standalone UI on the client's browser fron the server.
You can use a PopUpPanel to implement the msgBox functionality in a web app, but remember that every callback starts with a fresh instance of your app.
Upvotes: 2
Reputation: 45740
It turns out that Browser.msgBox(prompt)
is badly named. The only place this is supported is in a container-bound script (not stand-alone web app), and only when the container is a Spreadsheet.
In the UI Service, you are running outside of the IDE/Editor - you may be interested in this tutorial that describes one approach to debugging in that environment.
Upvotes: 1