sendBeacon
Summary
Asynchronously queues small amounts of HTTP data for transfer from the user agent to a web server. For example, it can be used to send analytics or diagnostics code without delaying the page's unload or affecting the performance of the navigation.
Method of dom/Navigatordom/Navigator
Syntax
var result = navigator.sendBeacon(url, data);
Parameters
url
- Data-type
 - any
 
DOMString
data
- Data-type
 - any
 
Must be of one of the following types:
- ArrayBufferView
 - Blob
 - DOMString
 - FormData
 
Return Value
Returns an object of type BooleanBoolean
Boolean
Boolean. Returns one of the following possible values:
| Return value | Description | 
|---|---|
| true | The HTTP data was queued for transfer. | 
| false | The HTTP data was not queued for transfer. | 
Examples
This example queues data for the server on the pagehide event.
function() {
  window.addEventListener('pagehide', logData, false);
  function logData() {
    navigator.sendBeacon(
      'https://putsreq.herokuapp.com/Dt7t2QzUkG18aDTMMcop',
       'Sent by a beacon!');
   }
}();
Related specifications
- Beacon
 - W3C Working Draft
 
Attributions
Portions of this content come from HTML5Rocks! article