Search code examples
htmlvalidationhref

invalid html (href target tag)


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?


Solution

  • 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.