This is just one reason more people need to embrace jQuery.
Here is an easy way to replace target=”_blank” in external links on your site. jQuery makes this a cinch! This is required if you choose to write strict XHTML.
I’m personally starting to clean much of my site up, this one of those easy fixes that is very easy to implement. 😉
Make certain this all goes in the head of your page or template…
This first part calls the jQuery resources on Google’s servers THX Google! – note you don’t have to do this part if you have the jQuery files hosted locally :
http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"
This second part is the nitty gritty:
$(function() {
$('a[rel*=external]').click( function() {
window.open(this.href);
return false;
});
});
The last thing you will need to do is… tag the links you want to open in a new window with:
rel="external"
Matt is a Systems Development Director for a multinational franchise. Matt has lived and worked in Hawaii, Chicago, South Florida and currently resides outside of Atlanta. He enjoys his hobbies including Technology, Gadgets/EDC, Fountain Pens, Wetshaving, Clocks, Antiques & Coffee. He even roasts his own coffee weekly.
Leave a Reply