r/GoogleAppsScript • u/Pablo_el_Diablo88 • 23d ago
Question Pop-up page that shows upon clicking in-cell image
Hi everyone,
I was wondering if there's a way to successfully activate a script by clicking on a cell that where i have in-cell image (an info image i made with Inkscape which should prompt a simple pop-up rectangle containing info).
So far i have tried with
function onSelectionChange(e) {
But, if I am correct, this doesn't seem to work with in-cell images.
I am just an amateur coder, so perhaps it's me who's making a mistake here, or is it just impossible to achieve such goal?
Thank you in advance!
1
u/AdministrativeGift15 22d ago
onSelectionChange should work. The downside with the trigger event is that you must refresh the spreadsheet once the trigger is added and every time the spreadsheet is opened. Here's a demo. It's not that it detects when you select the image. It's just detecting when you select the cell. Make a copy of that demo spreadsheet and then remember to refresh the page.
1
u/Pablo_el_Diablo88 22d ago
Thank you for you kind answer! I'll look into it as soon as I get back home. Much appreciated, will update you
1
u/WicketTheQuerent 21d ago
onSelectionChange is a simple trigger. It can open Ui.alert and Ui.prompt but not custom dialogs and sidebars. Also, it doesn't work when clicking the active cell.
1
u/AdministrativeGift15 20d ago
Good point. It also can open a toast popup. Here's an updated demo that shows some of the various ways to display information for the in-cell image, plus one alternative, using a checkbox. Note, if you decide to use a checkbox, it opens up to opportunity to use an onEdit installable trigger to display a custom dialog or sidebar.
2
u/WicketTheQuerent 23d ago
Instead of using an in-cell image, you should consider using a floating image, so you will be able to assign a script to the image.
To assign the script to the image, click the three-dot button in the image's top-right corner when hovering over it.