Reputation: 1097
I need to intercept all the events triggered on a page and to stop them; then I would like to send an XML message to a servlet that will return multiple clients. Once the message is received, the event is run normally.
So I have two problems: intercept and stop all the events and then trigger the event delayed.
To listen for a click on any element on the page I thought I would add a click
listener on $(document)
which composes the correct XML message: but in this way i intercept the event on top level of bubbling!
preventDefault
/stopPropagation
method, it is executed after the execution of event? How can I stop the event?event.target
method returns the document element or the element that triggers the event initially?Then, If I compose the XML message using the target and the type of the event, when a client receive the message and triggers it programmatically, this can unleash a loop?
UPDATE: the answer to the second question is given by http://www.quirksmode.org/js/events_properties.html where it is written:
Even if an event is captured or bubbles up, the target / srcElement always remains the element Took place on the event.
Upvotes: 1
Views: 406
Reputation:
To determine which element triggered the event use this in the event callback:
console.log("LOG|Event> " + "target: " + event.target);
if(event.target.id) {
console.log("LOG|Event> " + "target.id: " + event.target.id);
}
For cross browser please reference:
http://www.quirksmode.org/js/events_properties.html
Upvotes: 2