Hyperlinks in accordance with Web standards (reposted)

xiaoxiao2021-03-06  44

In HTML 4.0 Strict and XHTML 1.0 Strict, it is not allowed to use Target properties in the tag, which is an annoyed thing to make web designers. It is still allowed in the specification of the transition. But through a certain method, we It can solve this problem. The Target property is taken in HTML4.0 specification. But it adds another property: REL. This property is used to specify the relationship between the document containing the link and the link document. Definition The value of its property (such as: next, previous, chapter, section), most of these properties are used to define the relationship between the individuals in a large document. In fact. In fact. It is allowed to use free developers in the specification. Non-standard attribute values ​​do specific use. Here, we use a custom value External to mark a link for the REL property, used to open a window. Do not meet the latest web standard link code: External Link uses the REL attribute: External Link Now we build a new Web standard new The link of the window, we also need to use JavaScript to implement a new window. Script To implement, when you are loaded, find all those we defined as rel = "external". First we have to judge Browser .IF (! Document.GtelementsBytagname) return; getElementsBytagname is an easy way in the DOM1 standard, and it is supported by most browsers now, because some old browsers such as Netscape 4 and IE4 do not support DOM1, So we must exclude these older versions of browsers by determining this method. Next, we get the tags in the document through the getElementSbyTagname method: var achors = document.GtelementsBytagname ("a"); Anchors Assigning an array containing each label, now we must traverse each label and modify it: for (var i = 0; i Tag IF (Anchor.getattribute ("HREF") && ANChor.getattri Bute ("Rel") == "External") Next. Establish a property value Target and assign a value "_target": anchor.target = "_blank"; full code: function externalinks () {if (! Document.getElementsBytagname) Return VAR Anchors = Document.GtelementsBytagname ("a"); for (var i = 0; i


New Post(0)