make image clickable in google spreadsheet

user3533434 picture user3533434 · Apr 20, 2014 · Viewed 17.9k times · Source

I try to make clickable an imported image into Google spreadsheet. When I click it to take me to another website.

I was able to: - insert the image - to 'Assign script' to it - that looks like this:

function showMessageBox() {
  Browser.msgBox('You clicked it!');
}

When I click the image the above message comes up. However I need a script that I can assign and opens an outside url when image clicked.

Is there such a script available?

Answer

John picture John · Dec 9, 2014

These are the two solutions I was able to come up with:

(1) Assign this script to your image and replace the link with your own. It requires one more user click, but it's probably the best you can do. Caja locks down everything output by the HTML Service pretty tight, so things like window.location.replace("http://www.example.com"); or window.location.href = "http://www.example.com"; are a no go.

function redirectTest(){
  var htmlOutput = HtmlService
    .createHtmlOutput('<a href="http://www.example.com">Click Me!</a>')
    .setWidth(100)
    .setHeight(100);
 SpreadsheetApp.getUi().showModelessDialog(htmlOutput, " ");
}

(2) According to this source and this source, the following formula should work:

=HYPERLINK("http://www.example.com", IMAGE("https://www.google.com/images/srpr/logo11w.png"))

I couldn't get it to work in my tests, but the sources aren't that old.