


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>

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



As the importance of PHP in Web development continues to increase, PHP function library design has become one of the key issues in development. A good function library can not only improve development efficiency, but also ensure code quality and maintainability. Therefore, designing function libraries needs to follow some basic principles and standards. 1. A function library with good reusability should be reusable and can be used in different projects. Therefore, functions should be abstract and general and cannot be tied to a specific project or scenario. 2. Ease of use The function library should be easy to use and pass parameters

PHP functions can be classified according to various criteria: purpose (string processing, array processing, etc.), scope (built-in functions, user-defined functions) and return value (with or without return value). Practical case: The explode() function can split a string into an array with a specified delimiter.

How to judge the criteria for sticky positioning? Revealing the key elements of sticky positioning Introduction: Sticky positioning, as a market positioning strategy, plays a vital role in corporate brand promotion and market competition. However, how to judge the criteria for sticky positioning is a headache. This article will reveal the key elements of sticky positioning and help companies better judge the criteria for sticky positioning. 1. Understand the significance of sticky positioning Sticky positioning means that an enterprise generates strong identification and loyalty among consumers through its unique brand characteristics and core competitive advantages, thus forming a

The standard of sticky positioning refers to the ability of a company or brand to occupy a fixed position in consumers' minds for a long time in market competition and to stably maintain market share and brand loyalty. Sticky positioning is an important concept in marketing. It emphasizes that in a fiercely competitive market environment, companies need to establish their own unique positioning and establish close relationships with consumers to maintain competitive advantages. The core requirements of sticky positioning include the following aspects: Uniqueness: The positioning of a company or brand in the market must be unique and different from competitors.

Recently, there has been increasing discussion about generative artificial intelligence tools, especially after the release of several large-scale language models and image generators such as DALL-E or Midjourney. These inventions have once again put general artificial intelligence (GPAI) under the spotlight and once again raised hypothetical questions such as whether GPAI should be regulated. Before one explores the possibilities further, first understand the concept of GPAI, what it means, when was it introduced, etc. What is general artificial intelligence? Two years ago, in April 2021, the European Commission launched general artificial intelligence. The original AI bill proposal exempted creators of general artificial intelligence from complying with a number of legal instruments and other liability standards. reason

In web development, PHP is a widely used programming language. Its standard tags are special tag symbols in PHP code that are used to identify the beginning and end of PHP code. It is very important to have an in-depth understanding of PHP's standard tags because they directly affect the parsing and execution process of PHP code. This article will delve into PHP's standard tags and provide specific code examples to help readers better understand and use PHP programming. 1. PHP standard tags In PHP, the most commonly used standard tags are "

Title: Does the Go language meet the standards of upper-level languages? In recent years, Go language, as an emerging programming language, has received widespread attention and application. As a statically typed, compiled language, the Go language has unique advantages in concurrent programming, memory management, and code readability. However, in the eyes of some programmers, it does not fully meet the standards that upper-level languages should have. This article will discuss whether the Go language meets the standards of the upper-level language from several aspects, and discuss it with specific code examples. 1. Code simplicity. Upper-level languages are usually

Sticky positioning is a common web layout technique that provides a better user experience by keeping elements in a fixed position as they are scrolled. This article will analyze the standards, elements, and requirements for sticky positioning, and provide specific code examples. 1. Standard compatibility of sticky positioning: Sticky positioning should work normally on mainstream browsers, such as Chrome, Firefox, Safari, etc. Scroll effect: Elements should transition smoothly when scrolling to avoid flickering or jittering. Responsive design: Sticky positioning should adapt to different devices and screen sizes to ensure
