Page 1 of 1

Windows Detection

Posted: Thu Jan 01, 2004 5:27 pm
by Straterra
Is there a way in Javascript to detect if a certain popup window is open already?

Posted: Thu Jan 01, 2004 5:30 pm
by Pyrite
What I usually do is set a cookie for that popup when its open, and then I can check if the cookie exists at any point and do a windowname.close on it if it is. Works for me.

Posted: Thu Jan 01, 2004 5:37 pm
by JAM
Untested, but perhaps:

Code: Select all

mynewwindow=window.open('','','toolbar=no,scrollbars=no,width=300,height=150')
if (newWindow.closed) {
 // it is closed
} else {
 // it is not closed
}

Posted: Thu Jan 01, 2004 6:44 pm
by Straterra
This is what I have, but it doesn't work...

Code: Select all

<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
&#123;
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
 href=mylink;
else
 href=mylink.href;
newwindow=window.open(href, windowname, 'width=400,height=100,scrollbars=no,toolbar=no,status=no,resizable=no');
return false;
&#125;
//-->
</SCRIPT>
<SCRIPT TYPE="text/javascript">
if (newwindow.closed) &#123; 
&#125; else &#123; 
<BODY onLoad="popup('http://eckclan.sytes.net/cgi-bin/musicphp5.php', 'eckmusic')"> 
&#125;
</script>

Posted: Thu Jan 01, 2004 6:58 pm
by Pyrite
Like he said, Untested. I don't think closed() is a member function. And if it doesn't work, then it's probably not.

Try it my way.

Posted: Thu Jan 01, 2004 7:00 pm
by Straterra
Hm....but if I set a cookie, how will I know if the popup is closed? On the exit will it delete the cookie or something?

Posted: Thu Jan 01, 2004 11:20 pm
by Pyrite
Well, you set a cookie for that particular window. And delete it when you close it.

Posted: Fri Jan 02, 2004 10:48 am
by JAM
Actually needed something similiar today. This might be helpful.

Code: Select all

<html>
<head>
 <title>JavaScript Window Close Example </title>
</head>
<SCRIPT language="JavaScript1.2">
function popuponclick()
&#123;
 my_window = window.open("",
    "mywindow","status=1,width=350,height=150");
my_window.document.write('<H1>The Popup Window</H1>');
&#125;

function closepopup()
&#123;
 if(false == my_window.closed)
 &#123;
    my_window.close ();
 &#125;
 else
 &#123;
    alert('Window already closed!');
 &#125;
&#125;
</SCRIPT>
<body>
<P>
<A href="javascript: popuponclick()">Open Popup Window</A>
</P>
<P>
<A href="javascript: closepopup()">Close the Popup Window</A>
</P>
</body>
</html>

Posted: Fri Jan 02, 2004 1:51 pm
by Straterra
I have kind of modified your code..and I get errors :)

Front page :

Code: Select all

<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
&#123;
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
 href=mylink;
else
 href=mylink.href;
window.open(href, windowname, 'width=400,height=100,scrollbars=no,toolbar=no,status=no,resizable=no');
return false;
&#125;
//-->
</SCRIPT>
<BODY onLoad="popup('http://eckclan.sytes.net/cgi-bin/musicphp4.php', 'eckmusic')">
Second Page :

Code: Select all

<SCRIPT TYPE="text/javascript">
function closepopup() 
&#123; 
if(false == eckmusic.closed) 
&#123; 
    eckmusic.close (); 
&#125; 
&#125; 
</script>
I get errors on the second page that eckmusic isn't defined..Help?

Test if IMAGE is loaded on new page

Posted: Sat Jan 03, 2004 11:34 am
by onefocus99
You could always test to see if an image on that page is loaded :idea:
if it is loaded, then I guess that means popup window is open already.

This is just part of the code I use on my main page.
I wait for 2 images to load before making the 2nd image to move.

Code: Select all

<script language="JavaScript" type="text/javascript">
<!--
// 
var image1 = 10;
var image2 = 10;
function image1Loaded()
&#123;
   image1 = 11;
   if( (image1==11)&&(image2==12) )
   &#123;
      read2go();
   &#125;
&#125;
function image2Loaded() 
&#123;
   image2 = 12;
   if( (image1==11)&&(image2==12) )
   &#123;
      read2go();
   &#125;
&#125;
function read2go()
&#123;
   if( (image1==11)&&(image2==12) )
   &#123;
      for(var i=0; i<100000; i++)
      &#123;
         var today =  new Date();
         var secs = today.getSeconds();
         if( (secs % 5)==0 )
         &#123;
            movePointer();
            break;
         &#125;
         
      &#125;
   &#125;
   
&#125;
//...
// end hiding contents -->
</script>
I use modulus (%) so that sometimes the image will not move.


Opps I forgot to add:

<div id="pointing2" style="z-index: 10; position:relative; left:610px; width:40px; height:50px;">
<img src="images/rook.gif" onLoad="image2Loaded();">
</div>

<div style="position:absolute; top:210; margin-left: -30px;">
<img src="images/dimensionalized_1.gif" alt="" width="560" height="120" border="0" align="top" onLoad="image1Loaded();">
</div>

This really works :!: