views:

217

answers:

3

I have a popup window and in the page i have one the follow code in the body. The purpose is to have this popup windows close when user click on the image link, and a new page will be opened and directed to "http://www.somesite.com".

it works with IE and Chrome, however, in Firefox, the popup window is closed but no new windows is opened.

any idea?

<a href="http://www.somesite.com" target="_blank" onClick="javascript:window.close()"><img src="...something"/></a>
A: 

Perhaps your Firefox does not accept target="_blank" parameter? I don't remember exactly, but it can be turned off in about:config.

Tomasz Kowalczyk
it does support it, i removed the onclick event then it will open new window. but i have to find a way to close the current window thou.
Eatdoku
+1  A: 

Yes, I can repro this - interesting. setTimeout works around it:

onClick="javascript: setTimeout(window.close, 10);"

I can only guess that once the window closes (which happens before the hyperlink is followed) Firefox stops processing that page.

Edit: better make it 10ms delay - with 1ms Chrome doesn't close the window.

Evgeny
it works, thanks, i guess you are right it probably just stop execute other operation once it is closed. make sense ~
Eatdoku
+1  A: 

When you add some functionality to an element's click event via javascript, that functionality is executed before the default click event (in this case, opening a new page), in order to allow for the possibility of intercepting and overriding the default event. The default behavior will only execute when and if the event returns a boolean value of true.

In this case, the additional functionality would be to close the window and my guess is that Firefox chooses to interpret this as "we're all done here", so the click event never returns true, and thus the new page never gets opened.

Evgeny's suggestion of using a short timeout would allow the click event to return true before the window is closed, thus allowing the new window to open.

Ender