0

Is there a way to monitor click events on bookmarks in google documents with google apps script? I want to get bookmark id when someone selects a bookmark and than run some more code which needs that bookmark id to get processed.

Silko
  • 584
  • 1
  • 8
  • 26
  • You cannot capture click events in Google Apps Script. You would need to use a web app and the HTML Service with client side JavaScript to do that. – Brian Dec 16 '16 at 19:14
  • Can you provide an example maybe? – Silko Dec 17 '16 at 08:11
  • Web Apps through GAS are [well documented](https://developers.google.com/apps-script/guides/web). Essentially, you use GAS as server-side scripting and then JavaScript/HTML as the client side interaction. – Brian Dec 18 '16 at 00:57
  • Ok I'm not sure I'm doing it the right way but, I created a sidebar in a *.html file and include javscript with a click event listener. The script works, but it works only inside the sidebar. I want it to work inside the Google Document. – Silko Dec 18 '16 at 18:07

1 Answers1

0

With Brian Bennett's help I managed to solve this issue with Web Apps. There is a little bit more code to write but it works.

  1. Write a doGet function:

doGet function is called when a user visits your Web App. With doGet function I opened a document with ID given through get parameters and displayed it as html. To get a html of the document I used this function.

  1. Find and display bookmarks:

You can find bookmarks in the html of the document as html tag with id of the bookmark. I changed the css of all this tags so I could see them (change background, height, width or something like that).

  1. listen to click events on bookmarks with jquery or just javascript:

Listen to click events on those tags (bookmakrs) with jquery or javascript. If you use jquery, you need to import a jquery library. When click event happens get the id of the bookmark from the id attribute of the tag.

  1. Use that bookmark id as you wish...
Community
  • 1
  • 1
Silko
  • 584
  • 1
  • 8
  • 26