web development
Posted by: Abraham
Categories: HTML|Javascript
1 Apr 2010A 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;
});
Based in South Africa, we're a web-development company...
(2)
(3)
(1)
(5)
(4)
(1)
(1)
(14)
(1)
(8)
(7)
(17)
(1)
(4)
(2)
(2)
(1)