Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PopUp - download a file, close pop up and parent

Status
Not open for further replies.

gameon

Programmer
Feb 23, 2001
325
GB
Hi, I am trying to make a pop up that does the following:

- Pops up (on user req) (DONE)
- When you click a link it:
- starts downloading a file (DONE)
- Closes the parent window (NOT DONE)
- Closes its self (DONE)

I am using the follwing in the top of the pop up:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
this.focus();

function GoDownLoad(URL){
window.open(URL);
parent.close();
this.close();
}

</SCRIPT>

Where am I going wrong?

Cheers if you can enlighten me...

M@)
 
The parent window available from pop-up window with using window.opener. So, you try to close parent window with window.opener.close();
However, in this way parent window will rise a message box and ask do you really want to close parent window. To avoid this message for most browser use
window.opener.opener=self;
before closing parent window.

Regards,
Sergey Smirnov
 
Thank you for responding so fast.

I am testing for NS4.x

I'm now using the code (in the popup):

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
this.focus();

function GoDownLoad(URL){
window.open(URL);
window.opener.opener=self;
window.opener.close();
this.close();
}

</SCRIPT>

But, its still asking if I'm sure I want to close the window...

M@
 
You are right. Netscape 4.* does not like when popup window tries to close it. However, even Netscape leaves without noties if the close method is calling inside the parent window. So, if you want to close parent window just after the popup appears, you can insert the following code into the parent window:

function openNew() {
var winid=window.open(&quot;popup_window_here.html&quot;);
window.opener=winid;
window.close();
}

in this way you do not need to carry about parent window in your child code. Parent is already gone.

Regards,
Sergey Smirnov
 
Thanks for helping again. Unfortunatly the parent window only eeds to be closed if the link on the popup is clicked.

Can I have a function in the parent window (doing the closing), but call the function from the child window.

M@?
 
You could trick it and redirect the opening page window.opener.location.href= '/closebrowser.htm'to another url that simply has
<html>
<body onload=&quot;window.close()&quot;>
</body>
</html>

This will avoid the annoying &quot;are you sure....&quot;
 
Hi, it open a new window then closing it, rather than the opener window:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
this.focus();

var CloseURL = &quot;/#Request.RootDirectory#/help/utilities/close_browser.cfm&quot;;
function GoDownLoad(URL){
//open a new window with the download
window.open(URL);

// close the window that opened the pop up
window.opener=self;
window.opener.open(CloseURL);

//close the popup
this.close();
}
</SCRIPT>
 
Reply becuase you are telling to open a new window
var CloseURL = &quot;/#Request.RootDirectory#/help/utilities/close_browser.cfm&quot;;
function GoDownLoad(URL){
//open a new window with the download
window.open(URL);


In the javscript in the popup window put
window.opener.location.href= '/closebrowser.htm'

That wiull change the url of the window that opened the current window, to the url specified.

then in the page you send it to use the html I gave you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top