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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window opener and parent window close

Status
Not open for further replies.

zubz

Programmer
Mar 29, 2005
14
GB
Hi i have the following code as follows

function openWindow() {
window.open('confirm.cfm?fname=#url.fname#&lname=#url.lname#&pno=#url.pno
#&appid=#url.appid#&subid=#url.subid#&createdfname=#url.createdfname#
&createdlname=#url.createdlname#&salesfname=#url.salesfname#&saleslname=
#url.saleslname#','TheNewpop','toolbar=1,location=1,directories=1,status=
1,menubar=1,scrollbars=1,resizable=1');
top.opener = self;
top.window.close();
}

basicaly is there a way to make sure that the window.open runs fully to make sure that the new window is opened before the parent window is closed? Its just that this works most of the time but in some cases the window seems to have closed before the new window can be opened.

Thanks
 
Good to see you used the preview function and broke the nice long line up for us.

Anyway - there are several ways around this.

1. Use "setTimeout" to close the window after a specified delay (say, 1 or 2 seconds).

2. Poll the new window looking for a known element, and close only when you find it.

There are drawbacks to both:

- With (1.): You're not always guaranteed to be sure the window has opened, but it's a lot more guaranteed than with no delay.

- With (2.): You could end up with a CPU-intensive loop if the page loading was delayed for some reason.

Personally, I'd go with option 1.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
tahnks for the reply. could you show me a code example of how to achieve this?

thanks
 
To call something with a delay using setTimeout, pass your code (as a string) as the first parameter. The second parameter is the delay in milliseconds. So, the following example will run a function called "myFunction" after 1.5 seconds:

Code:
setTimeout('myFunction();', 1500);

I'm sure you can adapt this to do what you're after.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top