View Full Version : Closing parent window?
HughLazarus
06-26-2002, 02:37 PM
Is it possible for the window to close the window that created it?
I have a form that creates a 2nd window. After a certain amount of time I want this 2nd window to close the first one.
?
whackaxe
06-26-2002, 02:39 PM
to make a refernece to the windows parent (not to be mistaken with frames paretn) you use
window.opener.close()
using "window.opener" is equal to the "window" object of the first window
tamienne
06-26-2002, 02:56 PM
Just keep in mind that if the parent window wasn't called via window.open then you're going to get the security popup message that confirms you want to close the window.
There really isn't anything you can do about that window either.
Yes, there is - you can close a window like this without confirmation message:
<object id=closeWin type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Close">
</object>
<a href="javascript: void(0)" onclick="closeWin.Click()">Close this window!</a>
Saludo, piz
glenngv
10-10-2002, 03:42 AM
in the parent window:
window.open("URL","target","features");
window.opener = top;
setTimeout("window.close()",1000);
skeatt
11-22-2002, 10:30 AM
Originally posted by piz
Yes, there is - you can close a window like this without confirmation message:
<object id=closeWin type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Close">
</object>
<a href="javascript: void(0)" onclick="closeWin.Click()">Close this window!</a>
Saludo, piz
Piz, it works a treat for an onClick, however; I can't work out how one would be able to alter the code so that it closes the window "immediately after" you use javascript to created a child window.:confused:
If I put the Object into the header and use an onload=function it reports the "closeWin" isn't defined.
How else would you do it?
glenngv
11-22-2002, 10:51 AM
use the code I posted in my previous post (which I edited to make some corrections :D), it's from http://aspalliance.com/peterbrunone/impossible.asp
skeatt
11-22-2002, 11:27 AM
Glenngv...I tried this below: but it still gave the security dialog, I don't know where you previous post is because I found this one from a "search"
<SCRIPT LANGUAGE="JavaScript">
window.open("WhereAmI.asp","newWindow","height=520,width=730,toolbars=no,scrollbars=yes,resizable=yes");
window.opener = top;
window.close();
</SCRIPT>
glenngv
11-25-2002, 12:25 AM
what browser are you using? Check the aspalliance link that I posted. It listed what browsers that work with this code.
Quiet Storm
11-25-2002, 02:43 AM
Here's my code:
<html>
<head>
<script type="text/javascript">
function init() {
window.open('mywin.htm','myWin','height=400,width=400');
setTimeout("window.focus();closes.Click();",10000);}
</script>
</head>
<body onload="init()">
<object id="closes" type="application/x-oleobject"
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Close">
</object>
</body>
</html>
Place this code on the parent page. Don't forget the onLoad event.
Text in bold is editable.
Assigning the timeout to 10000 will close it after 10 seconds - adjust as needed.
Hope that helps! :D
skeatt
11-26-2002, 05:35 AM
I've cracked it in a clean way....that also allows netscape to close while using this snippet.
The trick is to call it after every thing has loaded and defined the classID, similar to your timing one but straight away, This part in the body triggers things....
<script language=Javascript>closeOpener()</script>
I noticed if you use the onload the <object id=... isn't defined.
Here is the full script......
<html>
<head>
<script type="text/javascript">
<!-- hide code
function closeOpener() {
newWin = window.open('url','mainWin','width=780,height=550,toolbar=yes,directories=no,status=no,scrollbars=no ,resizable=yes,menubar=no');
window.focus();
if (navigator.appName == "Microsoft Internet Explorer") {
closeWindowOpener.Click(); // use this for IE5
}
else {
self.close(); // used this for Netscape
}}
// -->
</script>
</head>
<body bgcolor="#207377">
<object id=closeWindowOpener classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" type="application/x-oleobject">
<param name="Command" value="Close">
</object>
<script language=Javascript>closeOpener()</script>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.