Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update offline-events.js #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions offline-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ function testConnection() {
xhr.open('HEAD', '/', false); // async=false
try {
xhr.send();
onLine = true;
if(xhr.status < 299){
onLine = true;
}else{
onLine = false;
}

} catch (e) {
// throws NETWORK_ERR when disconnected
// throws NETWORK_ERR when disconnected
onLine = false;
}

return onLine;
}

var onLine = true,
lastOnLineStatus = true;
lastOnLineStatus = true;

// note: this doesn't allow us to define a getter in Safari
navigator.__defineGetter__("onLine", testConnection);
testConnection();

if (onLine === false) {
lastOnLineStatus = false;
//lastOnLineStatus = false;
// trigger offline event
triggerEvent('offline');
}
Expand Down