


The web page opens in a new window target=_blank does not meet the standards_Experience exchange
"there is no attribute target for this element(in this HTML version)"
It turns out that under HTML4.01/XHTML1.0/XHTML1.1 strict DOCTYPE, target="_blank", target="_self" The syntax is invalid and we can only implement it through JavaScript.
A friend asked why target="_blank" is not allowed to be used? This attribute is very convenient. Haha, I don’t know what the W3C experts think. As far as I know, it is mainly about “ease of use and friendliness”, because foreigners think it is impolite to open a new window without the user’s consent or clear prompts. of. Regardless of whether this cancellation is reasonable or not, let’s look at the solution.
rel attribute
HTML4.0 adds a new attribute: rel. This attribute is used to describe the relationship between the link and the page containing the link, as well as the target of the link. rel has many attribute values, such as next, previous, chapter, section, etc. What we want to use is the rel="external" attribute. The code was originally written like this:
Open a new window
Now it is written like this:Open a new window
This is a method that complies with strict standards. Of course, it must be combined with a javascript to be effective.
javascript
The complete code JS is as follows:
function externallinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName(" a");
for (var i=0; i
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externallinks;
You You can save it as a .js file (such as external.js), and then call it through the external connection method: <script></script>
That's it.
Finally, the target="new" used by my website is allowed under the transitional DOCTYPE, but it does not meet the strict standard. I will use strict mode in the next revision and change all target="new" to rel="external".
This article refers to the following articles:
"New-Window links in a Standards-Compliant World" by Kevin Yank
"Standards-based Replacement for target="_blank" in External links 》
Updated on 2006.7.13
The homepages of many portal websites are all pop-up. I guess at least in China this concept cannot be changed for the time being. In this case, there is no need to add rel under each link. , the full code is as follows:
<script>//<![CDATA[ <BR>function externalLinks() { <BR> if (!document.getElementsByTagName) return; <BR> var anchors = document.getElementsByTagName("a"); <BR> for (var i=0; i<anchors.length; i++){ <BR> var anchor = anchors; <BR> if (anchor.getAttribute("href")) <BR> anchor.target ="_blank"; <BR> } <BR>} <BR>window.onload = externalLinks; <BR>//]]></script>

GooFonts is a side project signed by a developer-wife and a designer-husband, both of them big fans of typography. We’ve been tagging Google

Pavithra Kodmad asked people for recommendations on what they thought were some of the most timeless articles about web development that have changed their

Learning how to build GraphQL APIs can be quite challenging. But you can learn how to use GraphQL APIs in 10 minutes! And it so happens I've got the perfect

When a component lives in an environment where the data queries populating it live nearby, there is a pretty direct line between the visual component and the

Here's some legit CSS trickery from yuanchuan. There is this CSS property offset-path. Once upon a time, it was called motion-path and then it was renamed. I

Miriam Suzanne explains in a Mozilla Developer video on the subject.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),