title: How to get access to onclose event codes in Javascript onclose function?
body: <p>I have this simple WebSocket problem </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;meta charset="utf-8" /&gt;
  &lt;title&gt;WebSocket Test&lt;/title&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
      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('&lt;span style="color: blue;"&gt;RESPONSE: ' + evt.data + '&lt;/span&gt;');
          websocket.close();
      }
      function onError(evt) {
          writeToScreen('&lt;span style="color: red;"&gt;ERROR:&lt;/span&gt; ' + 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);
  &lt;/script&gt;
   &lt;h2&gt;WebSocket Test&lt;/h2&gt; 
  &lt;div id="output"&gt;&lt;/div&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>My question is that how can i have access to the web socket close codes ??
  as mentioned in this website </p>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference/CloseEvent" rel="nofollow">https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference/CloseEvent</a></p>
  
  <pre><code>1001    CLOSE_GOING_AWAY
  1000    CLOSE_NORMAL
  1005    CLOSE_NO_STATUS
  1006    CLOSE_ABNORMAL
  </code></pre>
  
  <p>Right now this is my onclose function </p>
  
  <pre><code>function onClose(evt) { writeToScreen("DISCONNECTED"); }
  </code></pre>
  
  <p>I have put up an alert as alert(evt) ,but i am not getting any close code .</p>
  
  <p>Could anybody please help </p>