0

生成されたプライベート メッセージ用のポップアップ ウィンドウを使用して Socket.IO チャットを作成してみます。ポップアップ ウィンドウ コードで windows.opener var を使用して、メイン ページの変数と関数にアクセスします。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
4

1 に答える 1

0

IE9 はネイティブ WebSocket をサポートしていません。そのため、socket.io ライブラリは xhr-polling システムでフォールバックを行います。これにより、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>

private.php で

window.receivedPrivate = function(data) {
    $('#private_data_recieved').append(data);
}
window.opener.popupReady();     

それは動作するはずです。ビュー論理index.phpを残してソケットの論理を移動しました。private.php私はそれをテストしましたが、動作します。

于 2012-10-19T20:36:25.503 に答える