views:

126

answers:

2

Hi all,

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 loading (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

A: 

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.

Mantorok
I tried self.close(), window.close(), top.close(), <any other name for the current window>.close()but the result it's the same. maybe I should add to the question the fact that I'm also using MS Ajax..
A: 

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;".