Published in: HTML
Very simple standard compliant way of opening a page in a new window. Since XHTML 1.0 Strict doesn't allow the target attribute in the tag. This method isn't recommended, use the DOM folks! See "Standard Compliant Way to Open a New Page Function" in my other snippets of code.
Comments
Subscribe to comments
You need to login to post a comment.

smaller, fail-safe script: return !window.open(this.href,'newwin');
That's all good and everything but you shouldn't be forcing new windows if the user doesn't want it. I especially hate it as well. If I want to open a link in a new window I already know how to do that.
You should only ever use it if you let the user know the link will open in a new window.
I Agree :)
I agree with noncon.
It's extremely annoying. Seriously, whenever I site wants to open a new window on me - let's say NASA, they do it a lot - I right click, copy the URI (which usually is a JavaScript call, i.e. javascript:openNASAWindow('externalflash/sts-1/index.html');, open a new tab, paste it into the address field, trim off the openNASAWindow() function, add http://www.nasa.gov/ to the beginning of the URI, and visit the paste. It doesn't take very long, but it's extremely irritating, and very bad usability.
Whilst I agree that if you MUST open a new window, you should use this method, I also believe that you should NEVER open a new window - yes, contradicting my first statement. In 2002, you might have wanted this code, but not now. EVERY major browser supports tabs, including just about every non-major browser. That's IE7 (and 8), Firefox, Opera, Safari. Also, OmniWeb, and Konqueror.
Could this be trimmed to this? window.open(this.href); return false
Hi Neal, Yes it can be trimmed down to that as the window name is optional. See here http://www.w3schools.com/HTMLDOM/metwinopen.asp
As has been mentioned before though, i wouldn't use this method to open a window, i'd use the DOM, make all your javascript unobtrusive. It's not recommended that you open a new link in a new window, if a user wishes to do this they can make that choice. If you are opening in a new window atleast give some input to the user that this will happen.