Http://kaifage.com/notes/76/navigator-sendBeacon.html
such as some statistical systems, when the page unload, if you want to report the current data, the use of xhr synchronous escalation, will block the current page jumps, using new image may encounter aborted, resulting in a failure to send successfully.
Now, you can use a browser to provide a more concise Sendbeacon method for sending guarantees. The Sendbeacon is asynchronous and does not affect the jump speed of the current page to the next page, and is not restricted by the same domain.
Window.addeventlistener (' Unload ', Logdata, false);
function Logdata () {
Navigator.sendbeacon ("/log", analyticsdata);
}
Sendbeacon returns True if it successfully enters the send queue of the browser, or False if the total number of queues, the size of the data, is limited. After returning ture, it simply means that the sending queue is entered, and the browser tries to ensure that it succeeds, but that it does not have any return value. Currently, there is no specific data length limit standard.
In view of the current browser support, you need to do a downgrade support (such as XHR in synchronous mode, if not the same domain to support Cors):
Navigator.sendbeacon | | New Function (' var xhr=new xmlhttprequest (); Xhr.open ("POST", arguments[0],true); R.send (arguments[1]); ');
Current browser support for Sendbeacon (see latest progress: http://caniuse.com/#search =sendbeacon):
Chrome 37+
Firefox (Gecko) 31+
Internet Explorer does not support
Opera 24+
Safari does not support
Phone-side Browser not supported: Android browser support, but iOS is not yet supported
Google Analytics has used Navigator.sendbeacon () to report data:
http://www.thyngster.com/google-analytics-added-sendbeacon-functionality-universal-analytics-javascript-api/
Https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference?hl=zh-cn
Via
W3 Standard Description: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/Beacon/Overview.html
MDN Description: Https://developer.mozilla.org/en-US/docs/Web/API/navigator.sendBeacon
Using Navigator.sendbeacon () to escalate data