14 Nov, 2006
New-Window Links in a Standards-Compliant World
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
Source: Sitepoint
Love what you've just read? Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
Other similar posts that you might be interested in:
- Open link in a new window using jQuery
- 10 most useful Javascript snippets from snipplr
- 10 Useful jQuery Snippets
- Click to copy and open site script
- 10 Useful Javascript Snippets for your mobile websites
- Troubleshooting jQuery.get() Cache issue in Internet Explorer
- How to ‘Post on Facebook Wall’ on iPhone and Android using PhoneGap plugins
Hello! Welcome to Web development blog! My name is Ei Sabai and on this blog, I write about web development, mobile app development, latest web technologies and the likes. Read more 

