


_blank opening a new window does not comply with standards?_CSS/HTML
This article refers to the following articles:
- Kevin Yank's"New-Window links in a Standards-Compliant World"
- 《Standards-based Replacement for target="_blank" in External links》
The usual way to open a link in a new window is to add target="_blank" after the link. There is no problem when we use the transitional DOCTYPE (xh tml1-transitional. dtd), but when we use the strict DOCTYPE (xhtml1-strict.dtd), this method will fail the W3C verification, and the following error message will appear:
"there is no attribute target for this element(in this HTML version)"
It turns out that under the strict DOCTYPE of HTML4.01/XHTML1.0/XHTML1.1, target="_blank", target="_self" and other syntaxes are invalid, and we can only implement them 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="externa l" attribute. The original code was written like this:
Open a new windowNow write it like this:
Open a new windowThis is a method that conforms to the strict standard. 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<anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; } } window.onload = externallinks;
You can save it as a .js file (such as external.js), and then call it through the external connection method:
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".

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

The article discusses using CSS for text effects like shadows and gradients, optimizing them for performance, and enhancing user experience. It also lists resources for beginners.(159 characters)

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.

No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth.

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and
