How to open external links in a new window in Drupal

Posted by: 
Dominique De Cooman

Create a file containing this piece of javascript.

if (Drupal.jsEnabled) {
 $(document).ready(function() {
  $("a[@href^=http]").each(function() {
    if(this.href.indexOf(location.hostname) == -1) {
      $(this).click(function(){;return false;});

Next in your phptemplate_variables function located in the template php you add the code in this example function.
function _phptemplate_variables($hook, $vars) {
  if ($hook == 'page') {
        $vars['scripts'] = drupal_get_js();
    return $vars;
  return array();

Add new comment

Who are you?

By knowing who you are you will be directed to a page where we have displayed all our drupal services relevant to your professional identity.