Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Created August 22, 2013 03:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanJA/6302851 to your computer and use it in GitHub Desktop.
Save SeanJA/6302851 to your computer and use it in GitHub Desktop.
check if you are connected and you don't have a dead battery.
$('.my-form').submit(function(){
var battery = window.navigator.battery.level <= 0.05;
var connectivity = window.navigator.onLine;
var msg = '';
if(!battery){
msg = "you should probably plug in your computer";
}
if(!battery && !connectivity){
msg += ", "
}
if(!connectivity){
msg += " you don't seem to be online";
}
if(msg){
alert("Bugger... " + msg);
return false;
}
return true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment