Question: I am writing a web app and I built a script to tell the user they need to be online. I am using JavaScript and JQuery. It does not work. :( This is what I have:

```
var online = navigator.onLine;
$(document).ready(function() {
    if (online == 'false') {
        $('#wifiwarning').fadeToggle("fast");
    };
});

```

Answer: 
It appears [navigator.onLine](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine.onLine) returns a boolean value, but you are checking for a string. 

Instead of:

```
if (online == 'false')

```

you need to use:

```
if (online == false)

```
You need to repeat the check in a regular interval like, in your case you are checking the state only once during the page load, any changes to the online state after that is not detected and reacted to.

```
$(document).ready(function () {
    var $el = $('#wifiwarning'),
        visible = $el.is(':visible');
    //execute it every 5 seconds
    setInterval(function () {
        if (navigator.onLine && visible) {
            $el.fadeOut("fast");
            visible = !visible;
        } else if (!navigator.onLine && !visible) {
            $el.fadeIn("fast");
            visible = !visible;
        }
    }, 5000)
});

```