开发者

JS window.close() let IE hang

for reason I won't bore you with, I'm writing an asp.net application that must open some pages in new browser windows.

I managed to open them within a postback (don't ask why, I just needed to) with this code:

script = String.Format(@"window.open(""{0}"", ""{1}"");", url, target);
ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);

Now I have new windows each one with a button that should close it. I have simply an onclick="window.close()" (but that prompts me when I'm closing the browser) or window.open('','_self','');window.close() (horrible, I agree but it's the only way I found to avoid the JS prompt)

On firefox it works perfectly but on IE7 (the browser our customers have) after 2-3 times I use that button to close the window I can't open other windows (in both cases, with or without the JS prompt). With the method above it does nothing, and with a <a href="mypage.aspx" target="_blank">click me</a> a new window is opened but hangs on l开发者_开发技巧oading (it doesn't even calls the Page_Load).

What could be the cause? How can I solve this?

Thank you.

EDIT:

I forgot to mention that I'm using MS Ajax in most of the pages, and that may be the reason that forces me to use window.open('','_self',''); before window.close() I don't know if this could cause also the hanging of IE


EDIT: Ignore that, it does still prompt the user - sorry!

For your first issue about closing the window, have you tried:

self.close();

Not too sure about the hanging issue though, I use window.open() and have never experienced issues in IE7.


I finally came to a solution:

on the attribute assignment there was a return false; missing.

Now it works perfectly with "window.open('','_self','');window.close();return false;".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜