生成されたプライベート メッセージ用のポップアップ ウィンドウを使用して 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