Opening Links In a New Window

Contributor Icon Contributed by AlexTheBeast Date Icon December 2, 2003  
Tag Icon Tagged: HTML

Although I usually hate it, this is the standard html code to open a link in a new window.


Forcing users to open links in new windows is so wrong. However, there are times when it is useful. Here’s how you do it.

Standard Link Code:
Tech-Recipes.com

Open Link In New Window Code:
Tech-Recipes.com

The addition of the target=”_blank” does the dirty deed.

Previous recipe | Next recipe |
 
  • Anonymous
    Hello Alex,

    There are two things I'd like to say. First, forcing users into a new window can be good if you want them to see information on another site without them leaving yours. Of course, when they're done on the "popped-up" site and close the window, they'll be back on your site!

    Second, there's actually a better way to force this new window if you are using XHTML 1.0 or higher code. Simply putting target="_blank" in your anchor DOES work, but it does NOT validate with the W3C. The preferred way is to add a little javascript like this:
    <a onclick="this.target='_blank';" href="http://www.tech-recipes.com">Tech-Recipes.com


    That will do it, AND will validate.

    Cheers,

    Chris
  • ACPRathore
    it was a stroke of good luck tht i found the html code to open links in new windows here. thanx to AlexTheBeast. although he says he hates this standard method, it proved very useful for me
blog comments powered by Disqus