Created
November 23, 2012 19:25
-
-
Save ktkaushik/4136930 to your computer and use it in GitHub Desktop.
check if browser is WebSocket compatible
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
| $(document).ready(function() { | |
| if( typeof(WebSocket) != "function" ) { | |
| // Display error message here ! | |
| } | |
| }); |
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
| // Check if the user's browser is WebSocket(WS) compatible | |
| // http://bit.ly/SiWEDV for more info | |
| function isBrowserWSCompatible () { | |
| var isCompatible = false; | |
| if ("WebSocket" in window) { | |
| isCompatible = true; | |
| }; | |
| return isCompatible; | |
| }; |
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
| if ("WebSocket" in window) { | |
| // different ways to create WebSocket using Faye though | |
| var ws = new WebSocket("ws://example.com/service"); | |
| ws.onopen = function() { | |
| // Web Socket is connected. You can send data by send() method. | |
| ws.send("message to send"); .... | |
| }; | |
| ws.onmessage = function (evt) { var received_msg = evt.data; ... }; | |
| ws.onclose = function() { // websocket is closed. }; | |
| } else { | |
| // the browser doesn't support WebSocket. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment