Html Target Attribute not supported

2020-07-02 09:49发布

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?

标签: html target
7条回答
ゆ 、 Hurt°
2楼-- · 2020-07-02 10:23

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.

查看更多
看我几分像从前
3楼-- · 2020-07-02 10:27

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.

查看更多
霸刀☆藐视天下
4楼-- · 2020-07-02 10:32

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

查看更多
叼着烟拽天下
5楼-- · 2020-07-02 10:42

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.

查看更多
够拽才男人
6楼-- · 2020-07-02 10:42

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

查看更多
狗以群分
7楼-- · 2020-07-02 10:44

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.

查看更多
登录 后发表回答