vendredi 27 février 2015

How to use offline.js or online.js with a submit button?

While these (Offline or Online.js) keep constantly checking for internet connection by setting timeout, What I want them to do is to check network connection only when the user presses the SUBMIT button. I don't want any timeout that make them check for connection continuously.


Honestly, I have been checking out all the websites and stack overflow questions for weeks, but nothing could satisfy me and my last resort was to go with these js libraries. I'm kinda new to js so a little help would be much appreciated!


Right now, my code using Online.js looks like this



<script src="online.js"></script>

$("#submit2").click(function()
{
if(window.onLine === true)
{
console.log("You're ONLINE");
}
else
{
console.log("You're OFFLINE");
}
});


The online.js link for your reference: http://ift.tt/1FElOnP


Aucun commentaire:

Enregistrer un commentaire