Create a W3C validated anchor link with target=“_blank”

前端 未结 11 1767
臣服心动
臣服心动 2021-01-04 22:51

I have the following piece of HTML that creates a new window when clicked:

glide by the people
         


        
11条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 23:24

    Actually, the proposed here solutions with adding the "target" attribute through JavaScript are completely standards compliant!

    The thing is that according to the W3C DOM Level 1 specification the interface HTMLLinkElement DO have target attribute, although the A element from HTML 4.01 specification do not have it.

    So it's invalid to write "target" attribute in html file, but is valid to add it to the document tree later via DOM interfaces using JS.

提交回复
热议问题