I\'m trying to implement a WebSocket with a fallback to polling. If the WebSocket connection succeeds, readyState becomes 1, but if it fails, readyState>
readyState
readyState>
Just like you defined an onmessage handler, you can also define an onerror handler. This one will be called when the connection fails.
onmessage
onerror
var socket = new WebSocket(url); socket.onmessage = onmsg; socket.onerror = function(error) { // connection failed - try polling }