jQuery or JS handling browsers back button

10,269

Solution 1

In jQuery land:

$(window).unload( function () { /*code here*/ });

EDIT- There was a parentheses instead of a close bracket

EDIT - Removed Extra Semicolin

Solution 2

Have not tried but i guess this do what you want.

window.onbeforeunload = function () {
   // stuff do do before the window is unloaded here.
}

with jQuery you could try the .unload() function

The unload event is sent to the window element when the user navigates away from the page. This could mean one of many things. The user could have clicked on a link to leave the page, or typed in a new URL in the address bar. The forward and back buttons will trigger the event. Closing the browser window will cause the event to be triggered. Even a page reload will first create an unload event.

Share:
10,269
Dee
Author by

Dee

Updated on June 05, 2022

Comments

  • Dee
    Dee almost 2 years

    Any ideas how to intercept the browser back button via jQuery, so I can run my event function? I don't need to use jQuery BBQ or jQuery Address, only prevent the default behaviour and run it later after some animate.

    Thank you!

    d