insertImage, assignScript, many lines of, click on one. Which line?

24 views
Skip to first unread message

Bruce Axtens

unread,
Jun 20, 2019, 10:28:59 PM6/20/19
to Google Apps Script Community
I've written about this on StackOverflow. The bottom line is, when you've assigned as script to an inserted image, is there any way of detecting what column/line the mouse was at when the image was clicked?

Dimu Designs

unread,
Jun 21, 2019, 6:38:21 AM6/21/19
to Google Apps Script Community
Unfortunately no. The functions that are assigned as scripts, have no context of the image or cell where the click event occurred. Ideally we'd want the function to be invoked with an event object that can be inspected within the function body, but that is not currently the case. 

There is a feature request on Google's issue tracker, linked below, where you can star the issue to encourage Google to add this functionality. 

Clark Lind

unread,
Jun 21, 2019, 10:53:53 AM6/21/19
to Google Apps Script Community
I'm sure there is a creative way to do it. Are users entering data or otherwise doing anything to the sheet before the image is pressed? If so, then you could just use onEdit() to grab the current Row, and you already know your image column.

If not, then you're looking at browser-level stuff and capturing the POST request the page is making back to Google. I looked at what it is doing behind the scenes and it does use what looks like some kind of coordinate system to determine what part of the displayed web page (sheet) was clicked, but it is beyond me. You'd have to dig in to the actual sheet specifications and I don't think Google makes that level of detail publicly available.

If users are making selections, make it a two-step process:  1) click the checkbox on the appropriate row (gets you the row), and 2) click on image to ...[do your code]. I don't see any other way at this point.


On Thursday, June 20, 2019 at 10:28:59 PM UTC-4, Bruce Axtens wrote:
Reply all
Reply to author
Forward
0 new messages