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:
<a href="document.html" target="_blank"> Open a new window</a>
Now write it like this: <a href="document.html" rel="external">Open a new window</a>
This is a strict method. Of course, it must be combined with a javascript to be effective.
The complete code JS of javascript is as follows:
The following is the quoted content: 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: <script type="text/javascript" src="external.js"></script>
That's it.
Reason: Mainly due to "ease of use and friendliness" issues, because foreigners think it is impolite to open a new window without the user's consent or clear prompts.