Cross-window Javascript communication 2.0
Back in April 2005, I wrote about a JavaScript system to regain control of an orphaned popup window. A couple of days ago, Robert Emmery left a comment stating that he had a simpler solution that didn’t require the somewhat clumsy notifier mechanism. Of course, at first, I didn’t believe him. Surely, nobody can solve a problem that I thought was insolvable! ![]()
Anyway, I challenged Rob to produce an example that reproduced exactly what mine did and he did so I declare my solution officially obsolete. Here’s Rob’s solution:
In the main window:
var popupWin = null;
function openPopup() {
var url = "popup.htm";
popupWin = open( "", "popupWin", "width=500,height=400" );
if( !popupWin || popupWin.closed || !popupWin.doSomething ) {
popupWin = window.open( url, "popupWin", "width=500,height=400" );
} else popupWin.focus();
}
function doSomething() {
openPopup();
popupWin.doSomething();
}
In the popup:
self.focus();
function doSomething() {
alert("I'm doing something");
}
As you can see it’s much cleaner. Thanks Rob!
Rob is the founder of SpaceCatch Inc, a social networking service that will launch some time in January.
You can read about the original solution and it’s problem here.