[webkit-help] Perform an action when user clicks on node with mouse

Julien Chaffraix julien.chaffraix at gmail.com
Sun May 23 22:50:54 PDT 2010

>> This is a correct approach. If you choose it, I would recommend doing
>> everything in JavaScript by using a method to inject a custom script
>> from C++ (in Chromium this is WebView::addUserScript but the naming
>> varies a bit per port). You can listen to DOM mutation events on the
>> document to get notified for each new image (see
>> http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MutationEvent)
>> and add your click listener at that time.
> Following up on this, I understand how this works for _new_ images that
> I add to a document: my document listener will receive a DOM mutation
> event for each newly inserted image, at which point I can add my click
> listener. However, what happens if I'm loading a document with existing
> images?  I'd like the existing images (in addition to new images that I
> add to the document) to have click handlers as well.

You are right, mutation events are related to new images appended to
the tree. I thought that mutation events would be dispatched during
parsing but after some experiments, it looks like I was wrong.
If you can't use the mutation events approach when parsing, then you
are better off with using document.getElementsByTagName("img") (and
"image") to handle those elements at some point - for example when the
page is loaded.


More information about the webkit-help mailing list