window.close() in IE

D

David

Hey all,

I have a script that dynamically sets the window.onunload of the current
window to point to a function that, when run, will close another dependent
window (if it's opened). This works fine when I am hitting refresh on the
browser, as the onunload event for the window fires and closes the other
dependent window. However, if I close the window, it is still firing the
onunload event, but I am getting a javascript "Permission denied" error (and
since I have script errors always showing, I see it before the window
closes). Sometimes it closes the dependent window, sometimes it doesn't.
Any ideas what might be going on here or a workaround? The same code works
fine in Firefox and I have not tested it in anything else. The IE version
is 6 (with SP2).

Thanks,

David
 
A

ASM

David said:
if I close the window, it is still firing the
onunload event, but I am getting a javascript "Permission denied" error (and
since I have script errors always showing, I see it before the window
closes). Sometimes it closes the dependent window, sometimes it doesn't.
Any ideas what might be going on here or a workaround? The same code works
fine in Firefox and I have not tested it in anything else. The IE version
is 6 (with SP2).

may be with a timer ?

<body onunload="setTimeout('popup.close()',10);">

or

<body onunload="setTimeout('popup.close()',0);">

or

<body onunload="popup.close();
setTimeout('alert(\'I did close popup\')',100);">
 
D

David

ASM said:
may be with a timer ?

<body onunload="setTimeout('popup.close()',10);">

or

<body onunload="setTimeout('popup.close()',0);">

or

<body onunload="popup.close();
setTimeout('alert(\'I did close popup\')',100);">
Yea, I thought of the same thing and tried it, but if I put it in a
setTimeout the code never gets executed. I put an alert in and never saw
it. I tried 0, 10 and 100 for the times. I know that the line of code
where it sets the timeout is getting run because I put an alert after it and
I get that alert. This is really weird.

Anyways, after looking into it more, that's not actually where the problem
is. The problem is in the onunload code for the popup window. The popup
has an onunload that calls this function.

function closeCart()
{
if (window.opener)
{ window.opener.blCartIsOpen=false
window.opener.currCartSel=null
}
}

Now, I realized I had to add the window.opener part because I was getting an
error in Firefox as well that was saying that window.opener had no
properties. However, that condition solved the problem there. In IE, I am
still getting the Permission denied error. Somehow, it is getting through
the condition (meaning that window.opener still exists) but it is freaking
out when trying to set those variables. Any ideas what might be going on
here? I figure that if all else fails I can have the main window set a flag
that will keep this code from running when it closes it.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top