How to call a function before leaving page with Javascript

前端 未结 8 542
遇见更好的自我
遇见更好的自我 2020-12-05 13:50

I would like to execute a function before leaving page without showing a confirmation popup with Javascript only. I\'ve tried with the code below but it did

8条回答
  •  有刺的猬
    2020-12-05 14:12

    This is an example of how you could handle the navigate away. Notice how a div appears a little before the navigation occurs.

    window.onbeforeunload = function () 
    {
       $("#oi").append($('
    This is the child DIV
    ')); }
    
    
    The Main Div will receive another div before leaving the page

提交回复
热议问题