The target=”_blank” xhtml strict workaround

A simple Question with a simple answer :
How do I open links in a new tab or window without using target="_blank", so that my page can still validate as XHTML?

Answer:
There are a load of options on google, most of them pretty confusing. But consider the following HTML :

<a href="www.anvilstudios.co.za" id="link_id">link</a>

The best method is to use Javascript: 

window.open(this.href);

Implement it in the following unobtrusive and progressively enhanced way, in an external javascript file:

 
document.getElementById("link_id").onclick = function () {
    window.open(this.href); return false;
}

or when using jquery :

$("#link_id").click( function() {
    window.open(this.href);
    return false;
});

Leave a Reply