jQuery or JS handling browsers back button

后端 未结 2 1569
野性不改
野性不改 2021-01-14 17:31

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 be

2条回答
  •  生来不讨喜
    2021-01-14 17:55

    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.

提交回复
热议问题