You can detect your local connection state to the internet on any JavaScript ready devices such as mobile phones and web browsers. Use advanced parameters and register the following callbacks (which fire during connection state changes):
<div pub-key="demo" sub-key="demo" id="pubnub"></div>
<script src="http://cdn.pubnub.com/pubnub.min.js"></script>
<script>
(function(){
// listen for messages
PUBNUB.subscribe({ // connect to a channel channel : "channel_abc", // resubscribe and reconnect
restore : true, // message received callback : function() {alert(JSON.stingify(m))}, // conneciton lost
disconnect : function() {alert("Connection Lost!")}, // connection restored reconnect : function() {alert("And we're Back!")}, // connection established connect : function() { // send a message PUBNUB.publish({ channel : "channel_abc", message : "Hi from PubNub." }) }
})
})();
</script>