[removed] not working in chrome

后端 未结 9 705
遥遥无期
遥遥无期 2020-11-27 07:25

This is the code which i used for window.onbeforeunload......




        
相关标签:
9条回答
  • 2020-11-27 08:31

    Try this, it worked for me:

    window.onbeforeunload = function(event) {
        event.returnValue = "Write something clever here..";
    };
    
    0 讨论(0)
  • 2020-11-27 08:32

    It seems that the only thing you can do with onbeforeunload in recent version of Chrome is to set the warning message.

    window.onbeforeunload = function () {
        return "Are you sure";
    };
    

    Will work. Other code in the function seems to be ignored by Chrome


    UPDATE: As of Chrome V51, the returned string will be ignored and a default message shown instead.

    0 讨论(0)
  • 2020-11-27 08:32

    Try this. I've tried it and it works. Interesting but the Succes message doesn`t need confirmation like the other message.

    window.onbeforeunload = function() 
    {
        if ( window.XMLHttpRequest )
        {
            console.log("before"); //alert("before");
            var request = new XMLHttpRequest();
            request.open("POST", "exit.php", true); 
            request.onreadystatechange = function () {
                if ( request.readyState == 4 && request.status == 200 )
                {
                    console.log("Succes!"); //alert("Succes!");
                }
            };
            request.send();
        }
    }
    
    0 讨论(0)
提交回复
热议问题