Jump to content

Change all hyperlinks to open in new window?


aximbigfan

Recommended Posts

I use JavaScript for this, only because the target attribute is not supported in XHTML. So the way around it is to use JavaScript to set the target attribute. I also use jQuery, to speed up the process. To define links that are to open in a new window I use the rel attribute and make it equal external.

 

<a href="http://www.google.com" rel="external">Google</a>

 

Then the jQuery:

 

$(document).ready(function(){
$('a[rel="external"]').attr("target","_blank");			
});

Problem is that I would still have to change all the links so that they reference rel, right? I have a huge string with the html in it, and I need to search each <a out and insert a "target='_blank' into it. I don't care about XHTML. The page will always be viewed on FF.

 

chris

You got it, use regex. That's how I would do it.

 

Eventually, I'll mod it out to support any tag with a href directive in it. I just don't really get along with RegExp that well. Myabe I should take some time off and learn it..

 

Chris

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.