# Replacement for deprecated "target" attribute



## DrP (Jul 23, 2005)

When I want a link to open in a new window I have used target="_blank". I believe this attribute is deprecated. What should I be using instead if I wish to remain up to date?


----------



## -MaDcOw- (Aug 3, 2005)

DrP said:


> When I want a link to open in a new window I have used target="_blank". I believe this attribute is deprecated. What should I be using instead if I wish to remain up to date?


You could use a javascript alternative


```
<a href="website.com" 
       onclick="window.open(this.href); return false;"
       onkeypress="window.open(this.href); return false;">Words to be shown</a>
```


----------



## DrP (Jul 23, 2005)

I see, so there is no html alternative then?


----------



## brendandonhu (Jul 8, 2002)

Nope. I believe this is a separation of content and functionality thing, as its none of HTML's business what window a user wants to view a page in.


----------



## -MaDcOw- (Aug 3, 2005)

Actually it depends if your writing in XHTML or HTML as i believe that it is not deprecated in HTML, only XHTML :up:


----------



## DrP (Jul 23, 2005)

Thanks then. I'll do it all in JavaScript. I'm quite keen to keep as much style from the XHTML as poss.


----------



## namenotfound (Apr 30, 2005)

-MaDcOw- said:


> Actually it depends if your writing in XHTML or HTML as i believe that it is not deprecated in HTML, only XHTML :up:


Actually, some HTML doctypes don't allow it either.
No version of a "Strict" doctype has ever allowed the "target" attribute. So it doesn't matter if you use "HTML 4.01 Strict" or "XHTML 1.0 Strict" doctypes. You'd need to use a Transitional doctype (loose in older versions of HTML)

XHTML 1.1 is the same as XHTML 1.0 Strict just with more modules


----------



## brendandonhu (Jul 8, 2002)

DrP said:


> Thanks then. I'll do it all in JavaScript. I'm quite keen to keep as much style from the XHTML as poss.


I would recommend adding the target attribute as well. Many people have javascript disabled or have popup blockers stopping that, but nearly everyone can use the target attribute. This isn't an _error_ in validating your code, just a warning. Having a functional, usable website is more important than passing some validation test anyway. You shouldn't stick to standards at the expense of having a good site.


----------

