'beforeunload' Chrome Issue

前端 未结 6 1938
不思量自难忘°
不思量自难忘° 2021-02-07 08:40

I have this simple piece of code -

$(window).bind(\'beforeunload\', function(){
    alert(\"Good Bye\")
});

Works great with Firefox, IE8 but

6条回答
  •  别跟我提以往
    2021-02-07 09:03

    If you need to send some analytical data just before unloading the document, choose navigator.sendBeacon() method instead of XMLHttpRequest.

    sendBeacon() method is designed to perform non-blocking sending of a small amount of data.

    But check canIuse report first, since the method is not supported globally yet.

提交回复
热议问题