【发布时间】:2012-04-26 11:34:28
【问题描述】:
我正在尝试从 trial.domain.com 连接到 server.domain.com 上的 websocket
Firefox 中的 NS_ERROR_DOM_SECURITY_ERR:
"[Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "https://trial.domain.com/home Line: 454"]"
当我尝试建立 WebSocket 连接时:
try {
if (window['MozWebSocket'] !== undefined) {
socket = new MozWebSocket('ws://server.domain.com/chat');
} else {
socket = new WebSocket('ws://server.domain.com/chat');
}
trails = 0;
} catch(err){
trials++;
}
【问题讨论】:
-
你不应该使用用户代理嗅探来确定是否使用
MozWebSocket,你应该寻找WebSocket构造函数,只有当你找不到它时才尝试MozWebSocket构造函数。