Reputation: 503
I am trying to close a modeless dialog that I opened with the following:
var html = HtmlService.createHtmlOutputFromFile('dialog')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(150)
.setHeight(150);
DocumentApp.getUi().showModelessDialog(html, 'Help');
The dialog html looks like this
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Working on it...
</body>
</html>
Now I want to close the dialog, but I can't get it to work. This is what I have.
var html = HtmlService.createHtmlOutputFromFile('close');
And the close html looks like this:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
google.script.host.close();
</script>
</head>
<body>
</body>
</html>
I've tried the google.script.host.close with the '()' and without. Any ideas what I'm doing wrong?
Upvotes: 2
Views: 4876
Reputation: 1
An example of a script that closes a notification HtmlService after 3 seconds
function t2 () {
var output = HtmlService.createHtmlOutput('<b>Thanks for the feedback.<br><br>'
+'<p><input type="button" value="Close" onclick="google.script.host.close()" /></p></b>'
+'<script> setTimeout(function(){ google.script.host.close(); }, 3000); </script>')
.setWidth(300)
.setHeight(100);
SpreadsheetApp.getUi().showModalDialog(output, 'Completed');
}
Upvotes: 0
Reputation: 1280
This is a pretty easily fixed issue as far as I can see. You don't want to create a new HTML file to close the old one, you want to close the first one. What you should do is this.
First, open your dialog as you have been doing.
Second, put your host.close() in a function inside of your help.html:
function closeHelp() {
google.script.host.close();
};
Then, just find somewhere to close it. I normally just make a button at the bottom of any dialog box.
<button onclick="closeHelp()"> Close </button>
This will close your window.
Upvotes: 1