Is it possible to make all service links to be open at new window?
Ectar - June 21, 2007 - 22:25
| Project: | Service links |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | patch (code needs review) |
Description
instead same window... I don't want to move my visitors away from the site.

#1
we will plan something for this in the next release
#2
that would be cool!
#3
This would be a fantastic addition. Could be simple as a check box on the module configuration page.
#4
Here's how I modified this module to open each link in a new window.
In service_links.module, I modified the lines ending in //ACB. I added a 'target' parameter in the attributes array for the link. Hope this helps, and I hope I've done it right.
if ($nodelink) {
switch (variable_get('service_links_style', 1)) {
case 1:
$link = array(
'title' => $text,
'href' => $url,
'attributes' => array('title' => $title, 'rel' => 'nofollow', 'target' => '_blank') //ACB
);
break;
case 2:
$link = array(
'title' => '',
'href' => $url,
'attributes' => array('title' => $title, 'rel' => 'nofollow', 'target' => '_blank'), //ACB
'html' => TRUE
);
break;
case 3:
$link = array(
'title' => ' '. $text,
'href' => $url,
'attributes' => array('title' => $title, 'rel' => 'nofollow', 'target' => '_blank'), //ACB
'html' => TRUE
);
break;
}
}
#5
Attached is a patch that makes use of the external links filter module to force service links to open in a new window (applies target="_blank" via jQuery to ensure W3C compliancy -- target="_blank" is not compliant. Please review.
#6
While waiting for this feature you can override theme_service_links_build_link in your own theme. This means you don't have to hack the module at all. With phptemplate and current 5.x release of Service Links add this to your template.php:
<?php
function phptemplate_service_links_build_link($text, $url, $title, $image, $nodelink) {
global $base_path;
if ($nodelink) {
switch (variable_get('service_links_style', 1)) {
case 1:
$link = array(
'title' => $text,
'href' => $url,
'attributes' => array('title' => $title, 'rel' => 'nofollow', 'target' => '_blank')
);
break;
case 2:
$link = array(
'title' => '<img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" />',
'href' => $url,
'attributes' => array('title' => $title, 'rel' => 'nofollow', 'target' => '_blank'),
'html' => TRUE
);
break;
case 3:
$link = array(
'title' => '<img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /> '. $text,
'href' => $url,
'attributes' => array('title' => $title, 'rel' => 'nofollow', 'target' => '_blank'),
'html' => TRUE
);
break;
}
}
else {
switch (variable_get('service_links_style', 1)) {
case 1:
$link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow" target="_blank">'. $text .'</a>';
break;
case 2:
$link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow" target="_blank"><img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /></a>';
break;
case 3:
$link = '<a href="'. check_url($url) .'" title="'. $title .'" rel="nofollow" target="_blank"><img src="'. $base_path . drupal_get_path('module', 'service_links') .'/'. $image .'" alt="'. $text .'" /> '. $text .'</a>';
break;
}
}
return $link;
}
?>
#7
I want to follow up with #4, this worked for me. The bookmarks open up in a new window. Thanks!
#5 and #6 may work as well, I just applied the first answer.