View Full Version : close parent on popup
robertsont
07-15-2004, 07:13 AM
is it possible to have a parent window close when a pop up starts?
it is for an offline form, i have a main window which is opened by the user and this pops up a modeless window, however when i instruct the main window to close automatically so does the pop up!
any help anyone!?!?
regards,
tom
robertsont
07-15-2004, 07:16 AM
alternatively is there something that would close all IE windows or the parent window when the popup is closed?
T
coder5436uk
07-15-2004, 07:23 AM
you could use some javascript
window.opener.close()
only problem is I think this will always ask the user are they sure they want to close the page
here is a small HTML I wrote to try this out
first link opens and new instance of the page in another browser window, second link tries to close the first window
---------------------------------------------------------
<html>
<head>
<title>Test close</title>
</head>
<body>
<a href="close_parent.html" target="_blank">open new window</a><br>
<a href="#" onclick="javascript:window.opener.close()">close parent</a>
</body>
</html>
-------------------------
in answer to your second post:
you can use a function that triggers when the page (popup) is closed
<body onunload="javascript:window.opener.close()">
robertsont
07-15-2004, 07:32 AM
tried it out and it works a treat - thanks!
i see what you mean about the annoyin query.
anyone any ideas about avoiding this? I seem to remeber reading something about naming the page and this being sufficient to deem the page 'yours' and so will close without query???
T
coder5436uk
07-15-2004, 07:47 AM
Hi,
don't use these functions often so forgot about that !
here is the ammended code
this will make the window yours and able to be closed
-----------------------------------
<html>
<head>
<title>Test close</title>
<script>
window.name="mine";
</script>
</head>
<body>
<!-- this line is open a new windows with a name -->
<a href="#" onclick="javascript:window.open('close_parent.html','stillmine')" target="_blank">open new window</a><br>
<a href="#" onclick="javascript:window.opener.close()">close parent</a>
</body>
</html>
robertsont
07-15-2004, 09:22 AM
sorry about this,
i've tried the new script but it seems to come up with the same problem. query to check you want to close the window.
T
RysChwith
07-15-2004, 09:46 AM
It has always been my understanding that the query was a security feature of the browser itself to prevent a page from misdirecting you. It might be something that can only be disabled by changing the user's security preferences (something you cannot make your page do).
Rys
scoutt
07-15-2004, 10:03 AM
you can't and shouldn't close the parent (default) users window. very bad and if I went to your site and you did that to me, then that would be the last time I went there.
robertsont
07-15-2004, 10:06 AM
this is for an offline form emailed to clients. not to be used on the web just to make the form filling experience for the user a littler easier!!
i agree it's not the best practice for the web but if it's possible I don;t see why it shouldn't be used (with care)
:-)
Tom
coder5436uk
07-15-2004, 10:16 AM
Hi,
must have not seen this alert window.
This is the browser bringing up this alert window - it is browser security and you can't stop it.
One was would be to turn off your browser security but you can't really ask everyone that visits to do that !!! (for many reasons)
you can either
1, accept this limitation and live with it.
2, create a step through page
You could use a dummy page i.e. index.html which is a blank page.
this calls your actual menu page as a popup that you own and are able to control and can close when ever you wish because you own it.
This still leaves a problem of what to do with the first blank page
There is a more complex solution to this thread Here (http://www.htmlforums.com/showthread.php?s=&threadid=14898)
robertsont
07-15-2004, 10:22 AM
right. i've had a look at the alternative but i think this is no good for my purposes as it requires the user to to be online.
this security feature cannot be bypassed even if the user hits the X (close) button on the pop up window? i.e. hit close on the popup but closes both the popup and the parent?
Thanks anyway,
T
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.