[英]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. 出于某种原因,我不会厌烦您,我正在编写一个必须在新的浏览器窗口中打开某些页面的asp.net应用程序。
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) 我只有一个onclick="window.close()"
(但是当我关闭浏览器时会提示我)或window.open('','_self','');window.close()
(可怕的是,我同意,但这是我发现避免JS提示的唯一方法)
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). 在Firefox上,它可以正常工作,但是在IE7(客户使用的浏览器)上,经过2-3次后,我使用该按钮关闭了窗口,但无法打开其他窗口(在两种情况下,无论是否带有JS提示)。 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 loading (it doesn't even calls the Page_Load). 使用上面的方法,它什么也没做,并且用<a href="mypage.aspx" target="_blank">click me</a>
会打开一个新窗口,但会在加载时挂起(它甚至不调用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','');
我忘了提到我在大多数页面中都使用MS Ajax,这可能是迫使我使用window.open('','_self','');
before window.close()
I don't know if this could cause also the hanging of IE 在window.close()
之前,我不知道这是否还会导致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. 不过,我不太确定挂起的问题,我使用window.open(),但从未在IE7中遇到过问题。
I finally came to a solution: 我终于找到了解决方案:
on the attribute assignment there was a return false;
在属性分配上, return false;
missing. 失踪。
Now it works perfectly with "window.open('','_self','');window.close();return false;"
现在,它可以与"window.open('','_self','');window.close();return false;"
完美配合 . 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.