Fardin K.
Fardin K.

Reputation: 455

Capturing new requests in a HTML page

How can I capture a new request (e.g. link click, page refresh, etc.) in an html page?

Let's say I need to do some stuff when user decides to go to another page or refresh the current page.

Upvotes: 0

Views: 85

Answers (1)

Alnitak
Alnitak

Reputation: 339947

Look at the the window.onbeforeunload and window.onunload events

You can also capture any link clinks easily [jQuery sample]:

$('a').on('click', function() {
     // do your stuff

     // follow the link
     window.location.href = this.href;
});

Upvotes: 2

Related Questions