Cancel onbeforeunload event handler?

前端 未结 4 879
孤独总比滥情好
孤独总比滥情好 2021-01-07 18:41

I have an onbeforeunload event handler attached to the page which executes every time the page reloads / gets redirected.

window.onbeforeunload = function()          


        
4条回答
  •  Happy的楠姐
    2021-01-07 19:02

    To add:

    function f_beforeunload(e) {console.log("do something");}
    window.addEventListener("beforeunload", f_beforeunload);
    

    To remove:

    window.removeEventListener("beforeunload", f_beforeunload);
    

提交回复
热议问题