Click browser detection

How to detect click events (including back button) using javascript?

+3
source share
1 answer

You can detect clicks inside the page with a simple event handler click:

document.onclick= function(event) {
    // Compensate for IE<9 non-standard event model
    //
    if (event===undefined) event= window.event;
    var target= 'target' in event? event.target : event.srcElement;

    alert('clicked on '+target.tagName);
};

It is not possible for the web page script to detect clicks outside the page, such as the back button and another Chrome browser, for security reasons. To do this, you must be part of a browser extension.

+10
source

Source: https://habr.com/ru/post/1740757/


All Articles