Windows Detection

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Windows Detection

Post by Straterra »

Is there a way in Javascript to detect if a certain popup window is open already?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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
}
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post 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>
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post 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.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post 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?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Well, you set a cookie for that particular window. And delete it when you close it.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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>
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post 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?
onefocus99
Forum Newbie
Posts: 16
Joined: Tue Oct 07, 2003 11:09 pm
Location: Hamilton Ont., Montreal, Chibougamau,... PQ, Victoria BC, now Alberta Canada

Test if IMAGE is loaded on new page

Post 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 :!:
Post Reply