Forum Moderators: open

Message Too Old, No Replies

Detect if my popup window is opened or closed

Fail when parent window is reloaded...

         

tomda

11:59 am on Jan 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi

I have a link on my parent window that opens a popup window full of musics (great for listening music while browsing).

function open_zic(url) {
var largeur = 225;
var hauteur = 305;
var gauche = 0;
my_window = window.open(url,"popzic","width="+largeur+",height="+hauteur+",left="+gauche+",top="+0+",dependent=yes,resizable=1,scrollbars=1,toolbar=0");
write_zic('<img name="but2" src="'+baseURL+'images/sound.png" width="16" height="16" alt="Zic ON"><span class="xl" style="color:#339900;"><b>ON</b></span>&nbsp;&nbsp;<a href="javascript:close_zic()" style="color:#FF0000;"><b>OFF</b></a>');
}

As you can see, when someone clicks on ON, it opens the popup window and change layout of my ON/OFF text. ON is bigger and a link to close the window is added to OFF.

Now, I want to detect using BODY onload command to detect if popup is opened in order to show the correct ON/OFF status in the header of the parent window.

function load_zic_status() {
if(!my_window.closed) {
write_zic('<a href="javascript:open_zic(\''+baseURL+'radio.blog.2.5/radio.blog/index.php\')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<img name="but2" src="'+baseURL+'images/sound_mute.png" width="16" height="16" alt="Zic OFF"><span class="xl" style="color:#FF0000;"><b>OFF</b></span>');
} else {
write_zic('<a href="javascript:open_zic(\''+baseURL+'radio.blog.2.5/radio.blog/index.php\')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<img name="but2" src="'+baseURL+'images/sound_mute.png" width="16" height="16" alt="Zic OFF"><span class="xl" style="color:#FF0000;"><b>OFF</b></span>');
}
}

But I get an error message saying that my_window is undeclared. My guess is that my_window value is lost when parent window is refresh

Any idea why?
Any function that detect is popup window is opened?

Thanks

tomda

6:58 am on Jan 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An example is sometime shorter than a full explanation.
Please get the code below, test it and see what's wrong...
I really hope someone will be able to help me ;)

THE MAIN PAGE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>MAIN PAGE</title>
<SCRIPT type="text/javascript">
function write_zic(texte) {
document.getElementById('show_zic_status').innerHTML = texte;
}

function open_zic(url) {
var largeur = 225; var hauteur = 305; var gauche = 300;
my_window = window.open(url, "popzic", "width="+largeur+", height="+hauteur+", left="+gauche+", top="+0+", dependent=yes, resizable=1, scrollbars=1, toolbar=0");
write_zic('<span style="font-size:26px; color:#339900;"><b>ON</b></span>&nbsp;&nbsp;<a href="javascript:close_zic()" style="color:#FF0000;"><b>OFF</b></a>');
}

function close_zic() {
if(my_window.document) {
my_window.close();
write_zic('<a href="javascript:open_zic(\'popup.html\')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<span style="font-size:26px; color:#FF0000;"><b>OFF</b></span>');
} else {
write_zic('<a href="javascript:open_zic(\'popup.html\')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<span style="font-size:26px; color:#FF0000;"><b>OFF</b></span>');
}
}

function load_zic_status() {
if(!my_window.closed) {
write_zic('<a href="javascript:open_zic(\'popup.html\')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<span style="font-size:26px; color:#FF0000;"><b>OFF</b></span>');
} else {
write_zic('<a href="javascript:open_zic(\'popup.html\')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<span style="font-size:26px; color:#FF0000;"><b>OFF</b></span>');
}
}
</script>
</head>

<body>
<p>
<span id="show_zic_status">
<a href="javascript:open_zic('popup.html')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<span style="font-size:26px; color:#FF0000;"><b>OFF</b></span>
</span>
<br><br>
1 / Click on &quot;ON&quot; to launch the popup window.<br>
2/ Click on this link to refresh parent window <a href="test.html">Refresh</a>, normally the load_zic_status should check if popup is opened... But it is not working since &quot;var my_window&quot; is lost?
</p>
</body>
</html>

AND THE POPUP (TO BE SAVED AS POPUP.HTML)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<SCRIPT type="text/javascript">
<!--
function write_zic_parent(texte) {
opener.document.getElementById('show_zic_status').innerHTML = texte;
}

function exitpop() {
write_zic_parent('<a href="javascript:open_zic(\'popup.html\')" style="color:#339900;"><b>ON</b></a>&nbsp;&nbsp;<span style="font-size:26px; color:#FF0000;"><b>OFF</b></span>');
}
// -->
</script>
</head>
<body onunload="javascript:exitpop();">

</script>
</head>

<body>
<p>THIS IS THE POPUP
<br>
If you close it, text in opener window is modified</p>
</body>
</html>

Thanks