andrew
andrew

Reputation: 5176

Html Target Attribute not supported

I was just on w3Schools looking at target and found that it is no longer supported by any of the major browsers. A brief google search did not reveal the reason for this? Should I avoid the use of target all together?

Upvotes: 15

Views: 5695

Answers (7)

M.Ganji
M.Ganji

Reputation: 866

$(function () {
    $("a").attr("target","_blank");
});

Upvotes: 0

troynt
troynt

Reputation: 1912

It was briefly taken out of html5, but they put it back in. Feel free to continue using it as all browsers should support it.

See http://www.w3schools.com/tags/tag_a.asp ... You will see target attribute is still supported there.

Upvotes: 7

user536158
user536158

Reputation:

I went to w3School and i found that The target attribute is no longer deprecated in HTML5.

Upvotes: 0

Álvaro González
Álvaro González

Reputation: 146540

It is supported by most major browsers. It's just not part of the strict HTML specifications from the W3C. However, browsers implement it even when using a strict doctype. This fact is sometimes used to emulate its behaviour with JavaScript while keeping HTML that still validates:

    <a href="http://www.google.com" rel="external">This is an external link</a>

And:

var links = document.getElementsByTagName('a');
for(var i=0, len=links.length; i<len; i++){
    var a = links[i];
    if(a.getAttribute('href') && a.getAttribute('rel')=='external'){
        a.target='_blank';
    }
}

In transitional doctypes, no workaround is required.

Upvotes: 0

Kornel
Kornel

Reputation: 100170

target attribute is supported by all browsers.

It has been removed from HTML4 Strict and XHTML 1 Strict, because these don't allow frames, and because forcing new windows on users isn't always good idea (e.g. Back button in new window will be disabled, which confuses some users).

target has been added back in HTML5. You can use it, but don't abuse it.

It's OK if you want to open help page in new window on page that has a long form (you don't want users to lose content of the form), but it's not OK to force every link in new window in hope it'll make your page harder to leave.

And please don't try cheat validator by using scripts to open new windows. It gives same negative effect to users (or even worse if it breaks when JS is disabled), but is harder to detect and control than target.

BTW: Please don't treat W3Schools as authoritative. They're not affiliated with W3C in any way, and their tutorials often contain mistakes.

Upvotes: 9

Stephan Muller
Stephan Muller

Reputation: 27620

It's still allowed in regular HTML and transitional xHTML, but not in strict xHTML anymore. The idea behind this was that users like to choose for themselves how to open a link, and not have it forced upon them by the browser.

Upvotes: 1

Skorpioh
Skorpioh

Reputation: 1355

The <a> tags target attribute is still supported by all major browsers (@w3schools).

Upvotes: 0

Related Questions