Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Click on Browser

Tags:

javascript

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

like image 244
Sreejesh Kumar Avatar asked Apr 12 '10 12:04

Sreejesh Kumar


1 Answers

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

document.onclick= function(event) {
    // Compensate for IE<9's 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 impossible for web-page script detect clicks outside the page such as the back button and other browser chrome, for good security reasons. You would have to be part of a browser extension to do this.

like image 68
bobince Avatar answered Oct 23 '22 20:10

bobince