ie11 websocket连接建立时报SecurityError问题
这段代码在chrome和firefox下是没有问题的,但是换成ie11之后,在for循环那块,前6个次都成功了,但是从第7次到第10次全都失败了,
new WebSocket
返回异常
SecurityError
。
function Socket(wsUrl){
try {
this._connect(wsUrl);
} catch (e) {
console.warn(e);
try {
this._connect(wsUrl);
} catch (e) {
console.error(e);
}
}
}
Socket.prototype = {
_connect: function(wsUrl) {
if("WebSocket" in window){
this.io = new WebSocket(wsUrl);
}else if("MozWebSocket" in window){
this.io = new MozWebSocket(wsUrl);
}
if (this.io) {
this.io.binaryType = "arraybuffer";// talking binary
this._addEvent();
}
},
_addEvent : function() {
this.io.onopen = function() {
console.log("WebSocket connection opened!");
};
this.io.onclose = function(){
console.log("WebSocket closed!");
};
this.io.onerror = function(evt){
console.log(evt.toLocaleString());
};
}
};
var lserver = 'websocket服务器域名';
for(var i=0;i<10;i++) {
setTimeout(function(){
var socket = new Socket('ws://'+lserver+':8110/ws/conn');
},i*1000);
}
已有该昵称
10 years, 3 months ago