Reputation: 455
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
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