what can i put in beforeUnload?

后端 未结 4 1335
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 10:00

I would like to have an animation effect which starts when people leave a page.

I use this currently:

window.onbeforeunload = function (){
    alert         


        
4条回答
  •  情深已故
    2020-12-31 10:18

    onbeforeunload can delay the page unload in only one case: When a return statement with a defined value is returned. In this case, the user gets a confirmation dialog, which offers the user an option to not leave the page.

    Your desired result cannot be forced in any way. Your animation will run until the browser starts loading the next page:

    [User] Navigates away to http://other.website/
    [Your page] Fires `beforeunload` event
    [Your page] `unload` event fires
    [Browser] Received response from http://other.website/
    [Browser] Leaves your page
    [Browser] Starts showing content from http://other.website/
    

提交回复
热议问题