Target Blank for XHTML
Given that the target attribute for the anchor tag does not comply with the W3C recommendation, which in turn does not validate, creating a new window for a link is not possible using a Strict XHTML Doctype.
Solution
Instead of changing the Doctype you may use JavaScript to open a new window. Writing a script for each anchor link would be too time consuming so we automate the process by grabbing all the Anchor links and then looping through them to see if they contain the “targetBlank” class.
JavaScript
function int(){ //Create an Array with all the Anchor Nodes var anchors = document.getElementsByTagName("a"); //Loop through all the Anchor Nodes for(var i = 0; i < anchors.length; i++){ //If an Anchor Node contains the string "targetBlank" in it's class then assign the onclick event to it. if(anchors[i].className.search(/targetBlank/) != -1){ anchors[i].onclick = function(){ var href = this.getAttribute("href"); var blankWindow = window.open(href, ""); blankWindow.focus(); return false; } } } } window.onload = int;
CSS
This CSS is not required to make this entire solution function correctly. Simply for aesthetics the style sheet provides a small popup image to the right of each “targetBlank” link.
a.targetBlank{ padding-right:20px; background-repeat:no-repeat; background-position:right center; background-image:url("../imgs/popIcon.png"); }
XHTML
All that you need is to apply the name “targetBlank” class to an anchor link.
<a class="targetBlank" href="http://www.google.com">A new page to Google</a>











