If you need to open the link in a new window, we use taget = "_ blank" on a, but many people do not know that this is not in line with W3C specifications, the error message "there is no attribute target for this element (in this html Version)" is prompted when strict doctype (xhtml1-strict.dtd) Verification is used.
Therefore, the taget = "_ blank" is basically not displayed in many foreign articles ".The alternative solution is to use the newly added tag rel in html4.0 to indicate the relationship between the link and the page containing the link, and the target of the Link Opening. Rel has many attribute values, such as next, previous, chapter, and section, and nofollow, which is used to reject crawling down by search engine spider.(This is very important. In Wordpress, almost all user name links in comments are added with rel = nofollow, so it is futile to add comments to the blog to add external links). Now we want to use the rel = "external" attribute to indicate that the link will be opened in a new window. Of course, this is only a method that complies with the strict standard, but does not really enable the link in the new window. It also requires support from the scripting script.
Train of Thought: After loading the page, add target = "_ blank" To Rel containing the external a tag through Js. The jquery method is provided below,CodeAs follows:
<SCRIPT type = "text/JavaScript">Jquery (Function($ ){//External and target = "_ blank"$ ("A [rel * = External]"). ATTR ("target", "_ blank");});</SCRIPT>
The above is just the implementation method of jquery and also the method used by Benbo. the native method of js is as follows:
<SCRIPT type = "text/JavaScript"> Function Externallinks (){ If (! Document. getelementsbytagname) Return ; VaR Anchors = Document. getelementsbytagname ("" ); For ( VaR I = 0; I <anchors. length; I ++ ){ VaR Anchor = Anchors; If (Anchor. getattribute ("href ")&& Anchor. getattribute ("rel ") = "External") anchor.tar get = "_ Blank" ;} Window. onload =Externallinks; </SCRIPT>