[webkit-help] Perform an action when user clicks on node with mouse
emerick at gmail.com
Sun May 23 18:01:36 PDT 2010
Julien Chaffraix writes:
>> I'm trying to perform an action when a user clicks on a particular DOM
>> element in my document. In my specific case, when the user clicks on
>> an image in my application, I need to modify its "src" attribute. It
>> seems like the approach I need to take is to call addEventListener to
>> add a "click" event listener when adding my image element. In the
>> event listener, I could then change the "src" attribute as needed. Is
>> this the correct approach to take or is there a better way to
>> accomplish this?
> This is a correct approach. If you choose it, I would recommend doing
> 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
> 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.
Apologies if I'm just missing something obvious here!
More information about the webkit-help