external links and CCK Image link fields

I had been desparately trying to find a way to set external CCK Image link fields to open in a new window - without success.

I've found two code snippets for insertion in the page template here

http://www.drupalcoder.com/story/80-automatically-open-all-external-link...

and will create templates just for the two pages where they are needed.

Fingers crossed.  Anyone have any comments?

 

 

darren's picture

set the target

I've not used this field type but looking at the code for Image link field (line 44) it looks like you can set the target in the field settings. Set the target to "_blank".

 

 

thank you

Tha's a great suggestion, however I only need the exernal links to open in a new window. Ideally this could be set on a case by case basis. BTW, I've tried adding extlinks module, but it doen't affect the CCK fields.

I've also tried
$(function() {
$('a[@href^=http]').not('[@href*=thegatedigital.com]')
.addClass('external-link')
.click(function() {
window.open(this.href, '_blank');
return false;
});
});

in template.php but it broke the theme

futher suggestiosn welcome

inetdigital's picture

Why not have two different

Why not have two different fields, one for external links and one for internal links?

Failing that you can use a piece of javascript like below (straight from Google haven't checked this) to open all external links in a new window. Note that "external" here is actually just an absolute link, links to your website with the full path would open in a new window.

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=anchors.length-1; i>=0; i--) {
var anchor = anchors[i];
if (anchor.href && anchor.href.substr(0,7) == "http://")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
devdoneright's picture

I used this module...

I use this module which does the hard work for you using jQuery. It automatically detects external links and adds a external links icon. It also does a similar thing for mailto links. It has a simple config which enables you to switch this off for certain domains, etc.

Give it a try.

 

thank you

Soory to say but as in my 2nd pst above - I've tried adding extlinks module, but it doen't affect the CCK fields.

devdoneright's picture

Obviously, I didn't read it.

Obviously, I didn't read it.  sorry about that.