public
Last active

quick check for online status with jQuery

  • Download Gist
hasInternets.js
JavaScript
1 2 3 4 5 6 7 8 9 10
//quick online/offline check
function hasInternets() {
var s = $.ajax({
type: "HEAD",
url: window.location.href.split("?")[0] + "?" + Math.random(),
async: false
}).status;
//thx http://www.louisremi.com/2011/04/22/navigator-online-alternative-serverreachable/
return s >= 200 && s < 300 || s === 304;
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.