Javascript window close event rather than unload event for all browsers

前端 未结 2 1576
逝去的感伤
逝去的感伤 2020-12-06 06:46

I want to alert a user while the user tries to close the browser with out siginingoff or without saving some settings.

I am ding unload option in another page to ale

2条回答
  •  孤城傲影
    2020-12-06 07:06

    The Mozilla documentation indicates that you should set the event.returnValue instead of simply returning a string:

    window.onbeforeunload = confirmExit;
    function confirmExit(e){
        if(readCookie("onlineVD") == "playing" && Confirm_Delete=="0")
        {
            var msg = "You are leaving a video which is in play mode.Are you sure want to exit this page?";
            if (e) {
                e.returnValue = msg;
            }
    
            return msg;
        }
        else{
            Confirm_Delete="0";
        }
    }
    

提交回复
热议问题