Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open link in a window using script (Google Sheet)

I'm trying to create a function inside Google Script Editor that would open a link and keep getting ERROR messages

function myfunction() { browser.window.open("link");
}

like image 634
Alex Kors Avatar asked Oct 29 '25 14:10

Alex Kors


2 Answers

I was looking for the same thing and found the solution below.
In this case it opens the link in the cell, that is selected when you press the button.
You could however just change the "selection" part and insert a url directly.

function openTab() {
var selection = SpreadsheetApp.getActiveSheet().getActiveCell().getValue();

var html = "<script>window.open('" + selection + "');google.script.host.close();</script>";

var userInterface = HtmlService.createHtmlOutput(html);

SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Tab');
}

They seem to have tightened security however, when I try this in Chrome, the new window is blocked by the built-in pop-up blocker. And Firefox doesn't even seem to try and open the link.
The Firefox issue might however be because I haven't logged in on my google account in Firefox and it seems to require authorization to run any scripts attached to sheets.

Ref: https://www.youtube.com/watch?v=2y7Y5hwmPc4

like image 176
Bramako Avatar answered Oct 31 '25 12:10

Bramako


function openTab() {
var selection = SpreadsheetApp.getActiveSheet().getActiveCell().getValue();

var html = "<script>window.open('" + selection + "');google.script.host.close();</script>";

var userInterface = HtmlService.createHtmlOutput(html);

SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Tab');
}
like image 40
Nadir Ahmad Avatar answered Oct 31 '25 12:10

Nadir Ahmad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!