target=”_blank” replacement
This is hardly a new concept, but i decided to finally get around to validating as much of my wordpress themes as i could. One major falling point i noticed was i used a lot of target=”_blank” anchor tags.
Bellow is the replacement code to create a XHTML valid “open in a new window” script.
Create a new external javascript file an add the bellow code
function RelLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank") anchor.target = "_blank"; } } window.onload = RelLinks;
Call the Javascript file somewhere within your tags
<script src="/external.js" type="text/javascript"></script>
Replace all your target=”” attributes to a rel attribute
<a href="document.html" rel="blank">link</a>
Comments are closed here.