Sunday 15 February 2015

javascript - How to make all page elements not to react on clicks -


I am trying to create an extension with the 'pick' functionality: the user can click on any element on the page Expect to see it more

However, to make it usable, I have to stop the element from reacting on the click: I do not want to forward hyperlinks to any other page, to submit forms UPD: I only need it for Chrome

My Ideally, an event handler in body has capturing variable You have to bind and prevent the event from promoting / default behavior

You can get a reference of the element that was clicked with event.target :

  document.body.addEventListener ('click', function (event) {event.preventDefault (); event.stopPropagation (); console.log (event.target);}, true);   

The advantage is that this event handler is already starting, no matter if another event handler is bound to elements in the page (unless this page is identical The event does not link Headler to the body , but event handlers are generally bound to bubbling stage).

See more for more information.



No comments:

Post a Comment