...

View Full Version : popup windows - methods, checking to see if a parent or parent/parent is open



musher
06-06-2007, 06:22 PM
3 questions:
1. In popit.php I have two methods (type-1 & type-2) of opening a popup window both use the same script function is either call preferred or better?

2. In JS is it preferred or better to use {} ie:
if (this) doit;
or
if (this) {doit;}
I've seen it both ways. is it just a preference thing?

3. I have 3 windows that could be opened main (popit) and then pop1 and pop2. pop1 may or may not be called depending on a check that I will be doing (right now I just have links so I can manually check).
---- so a parent-child or a grandparent-parent-child window (correct terminology?) ----
The problem I'm running into is detecting if the main window popit.php has been closed I have taken a look at using something like if (opener && !opener.closed){ opener.reload();} plus current function popIt_close but no success. and I've looked at a few things like http://www.webreference.com/js/tutorial1/exist.html but still a bit confused.

popit.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
self.name = 'Element_win';
var popwin = null;

function popIt(url, winName, winWidth, winHeight) {
var width = winWidth;
var height = winHeight;
var left = (screen.width - width)/2;
var top = (screen.height - height)/2;
var params = 'width='+width+', height='+height;
params += ', top='+top+', left='+left;
params += ', directories=0';
params += ', location=0';
params += ', menubar=0';
params += ', resizable=0';
params += ', scrollbars=0';
params += ', status=0';
params += ', toolbar=0';
popwin = open(url, winName, params);
if (popwin && !popwin.closed) popwin.focus();
return popwin;
}
</script>
</head>

<body onload="alert('loaded')">
<p>
<a href="#" onclick="void popIt('pop1.php','ErrorWindow',200,200);">Open Screen-1 (Type-1)</a>
<br />
<a href="javascript: void(0)" onclick="popIt('pop1.php','ErrorWindow',200,200);">Open Screen-1 (Type-2)</a>
</p>
<p><a href="javascript: void(0)" onclick="popIt('pop2.php','EntryWindow',500,500);">Open Screen-2</a></p>
<p><a href="javascript: void(0)" onclick="window.close()">Close Window</a></p>
<p>Date (for reload check) -- <?php echo date('l dS \of MF Y h:i:s A'); ?></p>
</body>
</html>
pop1.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function popIt(url, winName, winWidth, winHeight) {
var width = winWidth;
var height = winHeight;
var left = (screen.width - width)/2;
var top = (screen.height - height)/2;
var params = 'width='+width+', height='+height;
params += ', top='+top+', left='+left;
params += ', directories=0';
params += ', location=0';
params += ', menubar=0';
params += ', resizable=0';
params += ', scrollbars=0';
params += ', status=0';
params += ', toolbar=0';
popwin = open(url, winName, params);
if (popwin && !popwin.closed) popwin.focus();
return popwin;
}
function popIt_close() {
var w = window.open('' , 'Element_win');
if (w && !w.closed) w.location.reload(true);
self.close();
}
</script>
</head>

<body>
<p>
-- This Screen will pop up if check-1 is True.
<br />
-- If check-1 is False it would go straight to pop2.php
</p>
<br />
<a href="javascript: void(0)" onclick="popIt('pop2.php','EntryWindow',500,500);self.close();">Open Screen-2</a>
<br />
<a href="javascript: void(0)" onclick="popIt_close();">Close and Reload Opener (popit.php)</a>
</body>
</html>
pop2.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function popIt_close() {
var w = window.open('' , 'Element_win');
if (w && !w.closed) w.location.reload(true);
self.close();
}
</script>
</head>

<body>
<p>
-- This Screen will pop up if check-1 is False.
<br />
-- If check-1 is True it would have gone to pop1.php first
</p>
<br />
<a href="javascript: void(0)" onclick="popIt_close();">Close and Reload Opener (popit.php)</a>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum