Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frenchcooc/dfe79d4f90ad65421164ef86b4974351 to your computer and use it in GitHub Desktop.
Save Frenchcooc/dfe79d4f90ad65421164ef86b4974351 to your computer and use it in GitHub Desktop.
function onOpen() {
SpreadsheetApp.getUi().createMenu("User Menu").addItem("Open url", "openUrl").addToUi();
}
function openUrl(){
var url = SpreadsheetApp.getCurrentCell().getValue();
var tmp = HtmlService.createTemplateFromFile("index");
tmp.url = url;
tmp.isUrl = /^(http|www)/.test(url);
var htmlOutput = tmp.evaluate();
SpreadsheetApp.getUi().showModelessDialog(htmlOutput, "title");
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<noscript>
<meta http-equiv="refresh" content="0; url=<?= url ?>" >
</noscript>
</head>
<body>
<div id="message"></div>
<script>
var isUrl = <?!= isUrl ?> ;
var url = <?= url ?>;
if (isUrl) {
var newWin = window.open(url, "_blank");
if(!newWin || newWin.closed || typeof newWin.closed=='undefined'){
document.getElementById("message").innerHTML =
'Pop-ups blocked! <a href="https://support.google.com/chrome/answer/95472" target="_blank">Enable</a>.';
} else {
google.script.host.close();
}
} else {
document.getElementById("message").innerHTML = `${url} is not an url!`;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment