Created
June 9, 2016 22:30
-
-
Save djom202/d8710c65a052d1a17bbcbc434af6a8d5 to your computer and use it in GitHub Desktop.
Verify Status Internet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.connStatus = { | |
| _status: null, | |
| waitForChange: function(_callback) { | |
| this.getState(); | |
| this.updateState(_callback); | |
| return this; | |
| }, | |
| updateState: function(_callback) { | |
| console.log('Init setInterval'); | |
| setInterval(function() { | |
| if (this._status != navigator.onLine) { | |
| this._status = navigator.onLine ? true : false; | |
| console.log('Cambio!', navigator.onLine); | |
| _callback(this._status); | |
| } else { | |
| console.log('Pendiente al cambio...'); | |
| } | |
| }, 200); | |
| return this; | |
| }, | |
| getState: function() { | |
| this._status = navigator.onLine ? true : false; | |
| return this; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <script src="connStatus.js"></script> | |
| </head> | |
| <body> | |
| <p id="state"></p> | |
| <script> | |
| connStatus.waitForChange(function(_status) { | |
| var condition = _status ? "ONLINE" : "OFFLINE", | |
| state = document.getElementById("state"); | |
| state.innerHTML = condition; | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment