By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,623 Members | 1,991 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,623 IT Pros & Developers. It's quick & easy.

window.close() in IE

P: n/a
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
Aug 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ASM
David wrote:
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);">
--
Stephane Moriaux et son [moins] vieux Mac
Aug 19 '05 #2

P: n/a
ASM Wrote:

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
Aug 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.