Try the onbeforeunload event:
http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript

This will execute before the user's request is actually sent, giving
them the option to cancel the request.
As mentioned, you can't really specifically listen for a refresh, only
"the leaving the page", which could mean refresh, back/forward button,
clicked on some other link on page or browser bookmark, etc. I don't
think it will work on browser close, though. That might be browser
specific, though. Haven't had the chance to test it.

On Oct 21, 9:20 am, KeeganWatkins <keeganwatk...@gmail.com> wrote:
> hi lukas,
>
> you can't specifically listen for refreshes, but you can listen for
> unload events. an unload event is dispatched when:
>
> - a link is clicked to navigate away from the page
> - the window.location property is changed
> - the tab is closed
> - the browser window is closed
> - etc
>
> to play around with it, add this to your code:
>
> jQuery(window).unload(function() {
>     alert("bye bye!");
>
> });
>
> note that it will fire in response to everything in the list above,
> but also in response to refreshes. hope that helps.
>
> On Oct 21, 11:38 am, lukas <animod...@gmail.com> wrote:
>
> > How can I catch with Jquery a user refreshing the page with his
> > browser? Thank you!
>
>

Reply via email to