无效的 html(href 目标标记)
我很好奇这应该如何正确完成。
我通过 w3 html 验证器运行了一个正在处理的页面,并收到一条错误消息
第 47 行第 54 列:属性“目标”存在,但不能用于此元素。**
<ul><li><a href="./jobops/1000 Design PM.pdf" target="blank">1000 Design PM</a></li>
您已在文档,但您使用的文档类型不支持该元素的该属性。此错误通常是由于错误地将“严格”文档类型与使用框架的文档一起使用(例如,您必须使用“过渡”文档类型来获取“目标”属性),或者使用供应商专有扩展(例如“ marginheight”(这通常通过使用 CSS 来修复以达到所需的效果)。
关于如何让链接打开新窗口但不使用目标标签的任何想法?
I've curious how this should be properly done.
I ran a page im working on through the w3 html validateor and I got one error message
Line 47, Column 54: Attribute "target" exists, but can not be used for this element.**
<ul><li><a href="./jobops/1000 Design PM.pdf" target="blank">1000 Design PM</a></li>
You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).
any idea on how i can have a link open a new window but not use the target tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用 JavaScript 打开新窗口,这样可以避免目标被删除的问题在现代 HTML 中无效。
然而,这绕过了人们警告他们新窗口(或阻止它们打开)的各种系统,因此您最好使用目标属性(并切换到允许它的 Doctype)。
更好的是让用户决定何时需要新窗口。除了令人烦恼的因素之外,它们还带来了可访问性问题。
You can use JavaScript to open new windows, which avoids the issue of target being invalid in modern HTML.
However, this bypasses various systems people have in place to warn them about new windows (or prevent them from opening) so you are better off using the target attribute (and switching to a Doctype that allows it).
Better still is to leave it to the user to decide when they want a new window. Aside from the annoyance factor, they do introduce accessibility problems.
不会严格验证,因为“目标”属性已被弃用。
相反,尝试类似于上述 onclick 解决方法的方法,但您也不需要其中的“_blank”。简单地说:
会起作用。弃用“target”的原因是因为 HTML 用于在语义上标记数据,而 target 属性则提供行为,这正是 javascript 的用途。
如果用户关闭了 javascript,则 URL 将在同一窗口中打开。
Will not validate strict because the 'target' attribute has been deprecated.
Instead, try something similar to the aforementioned onclick workaround, but you don't need the "_blank" in there either. Simply:
Will work. The reason for the deprecation of "target" is because HTML is used to semantically mark up data whereas the target attribute was providing behaviour, which is what javascript is for.
If the user has javascript turned off then the URL will simply open in the same window.
target
属性不属于 HTML 4 和 XHTML 1.0 以及 XHTML 1.1 严格变体的一部分。因此,您需要使用 JavaScript 来解决问题:
或者(将来)CSS 3(请参阅 超链接呈现模块):
The
target
attribute is not part of the Strict variants of HTML 4 and XHTML 1.0 as well as XHTML 1.1.So you would need to use a workaround using JavaScript:
Or (in the future) CSS 3 (see Hyperlink Presentation Module):
难道不是吗……
无论如何……您可以使用 javascript 打开一个新窗口,但这破坏了简单浏览的美感。如果我使用 Lynx 或其他东西浏览怎么办?
Shouldn't it be...
Regardless... You could open a new window using javascript, but that breaks the beauty of simple browsing. What if I'm browsing using Lynx or something?
根据 W3C 的说法,“target”属性在 HTML 5 中似乎不再被弃用:
http://www.w3.org/TR/html5-diff/
According to W3C, it seems that "target" attribute is not deprecated any more in HTML 5:
http://www.w3.org/TR/html5-diff/
使用:
破坏严格的 XHTML 验证方法。 这是一份详细说明的文档解决方法:
Using:
breaks strict XHTML validation methods. Here's a document detailing a workaround:
您可以使用这样的 JavaScript,而不是 target="_blank"(永远不会验证):
然后链接将在新窗口中打开,并且您的页面将验证。
未启用 Javascript 的用户(尽管只占所有用户的 2% 左右)仍然可以使用此方法访问链接。这家伙的评论很有道理:)
祝大家周末愉快......
Instead of target="_blank" (who will never validate) you could use javascript like this:
Then the link will open in a new window, and your page will validate.
The users who doesn't have Javascript enabled (even though that is only about 2% of all users), will still be able to follow the link with this method. The guy's have a good point in the comments :)
Have a nice weekend everyone...