As many of you know by now, the attribute ‘target’ will not validate in an XHTML document. This creates quite a few problems for us because we don’t always want people leaving our site entirely. With a simple JavaScript code you can easily open external links in new windows unobtrusively!
First, make a link with the class ‘external’.
<a class="external" href="http://www.mvied.com/">MVied Designs</a>
Now apply this to an external JavaScript file named external.js and upload somewhere on your site.
function init() { var links = document.getElementsByTagName('a'); for (var i=0;i < links.length;i++) { if (links[i].className == 'external') { links[i].onclick = function() { window.open(this.href); return false; }; } } } if(document.childNodes) { window.onload = init; }
And link to this javascript in your header with a script tag. Don’t forget to change the location of the javascript file to where you uploaded external.js.
<script type="text/javascript" src="http://example.com/js/external.js"></script>
Many thanks for your valuable information. I have been seeking for this for ages in many sites. Windows 7 is a great software ever. I recommend Win7Zilla to tweak Windows 7 effective