Even if you used (2), how would you know *when* the session variable was changed?
(1) is certainly a possibility. For it to work, you have to *HAVE* a reference to the popped up page. Which is easy to get when you open the popup:
var popup = window.open("...the url...", "_blank", "...settings..." );
popup.someFunction("this is the message"); // call someFunction in the popup window
Now, there *ARE* ways of getting a reference to an existing popup from a new page, but they are typically a pain in the patootie to get working cross browser.
An easier way is to instead have the popup call back to the opener window. And you could easily have it do so every, say, 100 milliseconds. Have the main window simply remember if its callback function has already been called, or not, and have it only return a meaningful value when it hasn't.
On the main page:
And then, in the popup:
var alreadyCalledForMessage = false;
function getMessage( )
if ( alreadyCalledForMessage ) return null;
alreadyCalledForMessage = true;
Fortunately, window.opener will remain correct even if the original code in that main window has long since been replace by a new page. And so if there is a JS function by the right name in that main window, it will get called.
function checkForMessage( )
if ( window.opener != null && window.opener.getMessage != null )
var msg = window.opener.getMessage();
if ( msg != null )
... do something with the msg ...
window.onload = setInterval( checkForMessage, 100 ); // check every 100 milliseconds
Will that do the job?