开发者

jQuery or JS handling browsers back button

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 af开发者_Go百科ter some animate.

Thank you!

d


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.


In jQuery land:

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

EDIT- There was a parentheses instead of a close bracket

EDIT - Removed Extra Semicolin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜