Windows Detection
Moderator: General Moderators
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Windows Detection
Is there a way in Javascript to detect if a certain popup window is open already?
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:
This is what I have, but it doesn't work...
Code: Select all
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
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;
}
//-->
</SCRIPT>
<SCRIPT TYPE="text/javascript">
if (newwindow.closed) {
} else {
<BODY onLoad="popup('http://eckclan.sytes.net/cgi-bin/musicphp5.php', 'eckmusic')">
}
</script>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()
{
my_window = window.open("",
"mywindow","status=1,width=350,height=150");
my_window.document.write('<H1>The Popup Window</H1>');
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
}
</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:
I have kind of modified your code..and I get errors 
Front page :
Second Page :
I get errors on the second page that eckmusic isn't defined..Help?
Front page :
Code: Select all
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
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;
}
//-->
</SCRIPT>
<BODY onLoad="popup('http://eckclan.sytes.net/cgi-bin/musicphp4.php', 'eckmusic')">Code: Select all
<SCRIPT TYPE="text/javascript">
function closepopup()
{
if(false == eckmusic.closed)
{
eckmusic.close ();
}
}
</script>-
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
You could always test to see if an image on that page is loaded
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.
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
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()
{
image1 = 11;
if( (image1==11)&&(image2==12) )
{
read2go();
}
}
function image2Loaded()
{
image2 = 12;
if( (image1==11)&&(image2==12) )
{
read2go();
}
}
function read2go()
{
if( (image1==11)&&(image2==12) )
{
for(var i=0; i<100000; i++)
{
var today = new Date();
var secs = today.getSeconds();
if( (secs % 5)==0 )
{
movePointer();
break;
}
}
}
}
//...
// end hiding contents -->
</script>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