
Originally Posted by
chol7024
Sorry my HTML knowledge is poor and now using HTML in Blogger. Can you share...
Just to clarify ... I did a site once that had many internal links (to other pages within the same site), such as
Code:
<a href="/contact/">contact us</a>
and lots of external links (to other sites) like
Code:
<a href="http://someothersite.com">bye bye</a>
Suddenly, the client demanded that all external links open in a new window (so that people wouldn't leave his site when they clicked an external link).
Instead of going through the whole site and adding hundreds of target="_blank" attributes to all those external links, I just added this simple code to the <head> of each page (which I did just once, because most of the <head> content was fed to each page via a single include file):
Code:
http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
$(document).ready(function(){
$("a[@href^='http']").attr('target','_blank');
});
</script>
That's a much simpler solution, even though it means the user will have do download the entire jQuery library! (In the case of the site, that was already being used for other purposes anyway, so I've just added that first line above to show how you could do this if you weren't already using jQuery on the site.)
Bookmarks