var conent =this; var websocket,datacode,datacodearray=[],changeRate=[],closePrice=[],change=[],volume=[]; // 首先判断是否 支持 WebSocket if ('WebSocket' in window) { websocket = new WebSocket(url); } else if ('MozWebSocket' in window) { websocket = new MozWebSocket(url); } else { websocket = new SockJS(url); } // 打开时 websocket.onopen = function(evnt) { console.log("websocket.onopen ");// 发送消息 websocket.send(JSON.stringify(msg)); }; // 处理消息时 websocket.onmessage = function(evnt) { }; websocket.onerror = function(evnt) { console.log(" websocket.onerror "); }; websocket.onclose = function(evnt) { console.log(" websocket.onclose "); };