This is a sample script for opening a site with new window using Google Apps Script. It is possible to open the site inside the opened dialog box using iframe. But in my situation, I had to open the site as new window. So I created this. As a sample application, it can think of like this. When the special keyword was inputted, open sites and files in Google Drive as a help window. In this case, the trigger installed onEdit()
is required to be used. I think that there are some other applications.
function myFunction() {
var js = " \
<script> \
window.open('https://tanaikech.github.io/', '_blank', 'width=800, height=600'); \
google.script.host.close(); \
</script> \
";
var html = HtmlService.createHtmlOutput(js)
.setHeight(10)
.setWidth(100);
SpreadsheetApp.getUi().showModalDialog(html, 'Now loading.'); // If you use this on Spreadsheet
// DocumentApp.getUi().showModalDialog(html, 'Now loading.'); // If you use this on Document
// SlidesApp.getUi().showModalDialog(html, 'Now loading.'); // If you use this on Slides
}
- This sample script uses
getUi().showModalDialog()
. So you can also use this script at not only Spreadsheet, but also Document and Slides.- For Spreadsheet
SpreadsheetApp.getUi().showModalDialog(html, 'Now loading.');
SpreadsheetApp.getActiveSpreadsheet().show(html);
- For Document
DocumentApp.getUi().showModalDialog(html, 'Now loading.');
- For Slides
SlidesApp.getUi().showModalDialog(html, 'Now loading.');
- For Spreadsheet
- When you use this, please be careful for
X-Frame-Options:SAMEORIGIN
.
@tanaikech Opening the link on a new tab after clicking on a custom menu item on Google Documents, straight, without the dialog box message.
For example after clicking this button for opening the link:
And opening it on a new tab without this dialog box appearing: