navigator.sendbeacon
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "navigator.sendbeacon", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Polyfill for navigator.sendBeacon()", | ||
@@ -5,0 +5,0 @@ "main": "sendbeacon.js", |
@@ -13,6 +13,2 @@ # Navigator.sendBeacon polyfill | ||
```bash | ||
bower install navigator-sendbeacon | ||
``` | ||
# Usage | ||
@@ -19,0 +15,0 @@ |
(function(root) { | ||
'use strict'; | ||
function sendBeacon(url, data) { | ||
function sendBeacon(url, data, _settings) { | ||
var xhr = ('XMLHttpRequest' in window) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); | ||
@@ -17,2 +17,15 @@ xhr.open('POST', url, false); | ||
} | ||
if (typeof _settings === 'object') { | ||
if (!isNaN(_settings.timeout)) { | ||
// xhr.timeout doesn't work for synchronous requests | ||
setTimeout(function() { | ||
if (xhr.readyState !== 4) { | ||
xhr.abort(); | ||
} | ||
}, _settings.timeout); | ||
; | ||
} | ||
} | ||
xhr.send(data); | ||
@@ -19,0 +32,0 @@ return true; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5973
65
20