Open Link in a Window Using Script (Google Sheet)

Google Apps Script to open a URL

You can build a small UI that does the job like this :

function test(){
function showURL(href){
var app = UiApp.createApplication().setHeight(50).setWidth(200);
app.setTitle("Show URL");
var link = app.createAnchor('open ', href).setId("link");
var doc = SpreadsheetApp.getActive();;

If you want to 'show' the URL, just change this line like this :

  var link = app.createAnchor(href, href).setId("link");

EDIT : link to a demo spreadsheet in read only because too many people keep writing unwanted things on it (just make a copy to use instead).

EDIT : UiApp was deprecated by Google on 11th Dec 2014, this method could break at any time and needs updating to use HTML service instead!

below is an implementation using html service.

function testNew(){

function showAnchor(name,url) {
var html = '<html><body><a href="'+url+'" target="blank" onclick="">'+name+'</a></body></html>';
var ui = HtmlService.createHtmlOutput(html)

Google Script to open URL in same window as Spreadsheet

According to the setTarget documentation:

"(setting a target to _self) will only work if the app is being shown as a standalone service. It will have no effect when called inside a dialog, such as in a Google Spreadsheet."

Apps Script intentionally prevents scripts from being able to switch the view of the current window, as a security measure.

Google Apps Script to open a URL based on a cell

From I would like to use that cell as a reference to my script (which opens url on a button). and How can I modify this script in order to get the link from the B2 cell?, when your script is modified, how about the following modification?


function openUrl( url="" ){


function openUrl(){
var url = SpreadsheetApp.getActiveSheet().getRange("B2").getValue();


  • getRange(a1Notation)
  • getValue()

Google Script for opening a URL in dedicated browser (Internet Explorer) by click in Spreadsheets

Although it's not possible to force open links in specific browser, it is possible to detect the user agent string as the previous answer states. You can use use HtmlService.getUserAgent():

function testInternetExplorer(){
var html = HtmlService.createHtmlOutput(js)
var ui = SpreadsheetApp.getUi();
var response = ui.alert('This app link is available only on Internet Explorer.\n Proceeding to use outdated browsers may cause serious damage to your device, data and privacy.\nAre you sure you want to continue?', ui.ButtonSet.YES_NO);
if(response == ui.Button.YES) {
ui.showModalDialog(html, 'Loading, please wait...');
} else {
ui.alert("Internet Explorer is not detected.\n Cannot proceed.")

Related Topics

Leave a reply