I try making Socket.IO chat using generated popup window for private message. I use windows.opener var in popup window code to acess variables and functions in main page. In Firefox and Chrome window.opener.socket.on(...) function successfully start from popup window code, but IE9 wont. Node.js server in background send and receive events. I use following code:
//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
IE9 does not supports native websocket. So the socket.io library do a fallback on xhr-polling system. This cause some problem in IE (honestly for me unknown).
However if you change approach to the problem like so:
in 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>
in private.php
window.receivedPrivate = function(data) {
$('#private_data_recieved').append(data);
}
window.opener.popupReady();
it should works. I moved the logical of socket in index.php
leaving in private.php
the view logical. I've tested it and it works.