websocket - How to get access to onclose event codes in Javascript onclose function? -


i have simple websocket problem

<!doctype html> <meta charset="utf-8" /> <title>websocket test</title> <script language="javascript" type="text/javascript">     var wsuri = "ws://echo.websocket.org/";     var output;      function init() {         output = document.getelementbyid("output");         testwebsocket();     }     function testwebsocket() {         websocket = new websocket(wsuri);         websocket.onopen = function (evt) {             onopen(evt)         };         websocket.onclose = function (evt) {             onclose(evt)         };         websocket.onmessage = function (evt) {             onmessage(evt)         };         websocket.onerror = function (evt) {             onerror(evt)         };     }     function onopen(evt) {         writetoscreen("connected");         dosend("websocket rocks");     }     function onclose(evt) {         writetoscreen("disconnected");     }     function onmessage(evt) {         writetoscreen('<span style="color: blue;">response: ' + evt.data + '</span>');         websocket.close();     }     function onerror(evt) {         writetoscreen('<span style="color: red;">error:</span> ' + evt.data);     }     function dosend(message) {         writetoscreen("sent: " + message);         websocket.send(message);     }     function writetoscreen(message) {         var pre = document.createelement("p");         pre.style.wordwrap = "break-word";         pre.innerhtml = message;         output.appendchild(pre);     }     window.addeventlistener("load", init, false); </script>  <h2>websocket test</h2>  <div id="output"></div>  </html> 

my question how can have access web socket close codes ?? mentioned in website

https://developer.mozilla.org/en-us/docs/websockets/websockets_reference/closeevent

1001    close_going_away 1000    close_normal 1005    close_no_status 1006    close_abnormal 

right onclose function

function onclose(evt) { writetoscreen("disconnected"); } 

i have put alert alert(evt) ,but not getting close code .

could please

try this:

function onclose(event) {     alert('onclose called' + event);     alert('code is' + event.code);     alert('reason ' + event.reason);     alert('wasclean  is' + event.wasclean); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -