Jquery html弹出窗口中的Socket.IO聊天

Jquery html弹出窗口中的Socket.IO聊天,jquery,node.js,popup,socket.io,Jquery,Node.js,Popup,Socket.io,我尝试使用生成的私人消息弹出窗口进行Socket.IO聊天。 我在弹出窗口代码中使用windows.opener变量访问主页面中的变量和函数。在Firefox和Chrome中,window.opener.socket.on(…)函数成功地从弹出窗口代码启动,但IE9不会。Node.js服务器在后台发送和接收事件。我使用以下代码: //in index.php var socket = io.connect('http://localhost:8080'); //oth

我尝试使用生成的私人消息弹出窗口进行Socket.IO聊天。 我在弹出窗口代码中使用windows.opener变量访问主页面中的变量和函数。在Firefox和Chrome中,window.opener.socket.on(…)函数成功地从弹出窗口代码启动,但IE9不会。Node.js服务器在后台发送和接收事件。我使用以下代码:

     //in index.php
    var socket = io.connect('http://localhost:8080');
     //other code
    $("#users .user").live('click',function(){
    //other code
    popUpWin[client_id]=window.open('private.php', client_id, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=300,height=400,left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');         
    //other code        
    });


    //in private.php
    //other code
    window.opener.socket.emit('popup',window.opener.client_id);//This work!         
    window.opener.socket.on('private_message', function (data) {This not work, private message event is send!
        $("#private_data_recieved").append('<div><b>'+data.nick+':</b> '+parseString(data.message)+'</div>');
        playSound();                        
    }); 
        //other code
//在index.php中
var socket=io.connect('http://localhost:8080');
//其他代码
$(“#users.user”).live('单击',函数()){
//其他代码
popUpWin[client_id]=window.open('private.php',client_id',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizeable=no,copyhistory=yes,width=300,height=400,left='+left+',top='+top+',screenX='+left+',screenY='+top+');
//其他代码
});
//在private.php中
//其他代码
window.opener.socket.emit('popup',window.opener.client\u id)//这工作!
window.opener.socket.on('private_message',函数(data){这不起作用,private message事件是send!
$(“#收到私有数据”).append(''+data.nick+':'+parseString(data.message)+'';
播放声音();
}); 
//其他代码

IE9不支持本机websocket。因此,socket.io库在xhr轮询系统上执行回退。这导致IE出现了一些问题(老实说,我还不知道)

但是,如果您改变了解决问题的方法,如下所示:

在index.php中

var EVENT = module.exports.EVENT;
var socket = io.connect('http://78.46.135.87:8060');
var win;
socket.on('private_message',function(data) {
    win.receivedPrivate(data);
});

function openPrivate() {
    win =window.open('private.php', 1, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=300,height=400');         
}
function popupReady() {
     socket.emit('popup',"1");
}
// and html
<a href="#" onclick="openPrivate()">Open private</a>

它应该有效。我在
index.php
中移动了逻辑套接字,在
private.php
视图中留下了逻辑套接字。我已经对它进行了测试,它可以正常工作。

您有swf文件作为备用?在您的
socket.io.js
的同一文件夹中,您应该会看到
WebSocketMain.swf
文件没有类似的内容,我使用npm方法安装模块。请描述一下.swf文件是如何解决我的问题的?查看我的答案(很抱歉,socket io的官方网站现在已经关闭,我无法搜索官方答案:)不工作:(这里有一个类似的例子:,你能在JSFIDLE上上传你的测试吗?不工作:(我这里也有同样的问题。请告诉我错误在哪里?新窗口中的消息没有附加,我现在不知道原因。是的…在您的代码中尝试移动
$(popUpWin)。就绪(函数(){
在单击处理程序中
window.receivedPrivate = function(data) {
    $('#private_data_recieved').append(data);
}
window.opener.popupReady();