External links don't open new window

danielb - January 29, 2009 - 06:32
Project:Alinks
Version:6.x-1.0-rc1
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

There is not target="_blank" added to external links.

HINT: wtf is this doing in hook_menu?

  drupal_add_js('
$(function(){
  $(\'a[@rel$="external"]\')
    .click(function(){this.target = "_blank";
    });
});', 'inline');

And why do you even need javascript?

Use the l() function's 3rd param.

#1

cssd - February 4, 2009 - 10:34

I found this same issue and thanks to the 'hint' at the solution from danielb I think I have fixed it.

Well - it works for me anyway!

Hope this is useful...

The code changes are as follows;

/* remove or comment out this as can make external link in PHP below - fix

  drupal_add_js('
$(function(){
  $(\'a[@rel$="external"]\')
    .click(function(){this.target = "_blank";
    });
});', 'inline');

*/

and;

/* Make external link in PHP here rather than in javascript code - fix
** this is the old 'external link' definition - can be commented out or removed, below it is the new code - including 'target' => 'blank'

          $alink_url[] = l('alink_check\1alink_check',
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check',
                           array(
                           'attributes' =>array('class' => 'alink_check'.str_replace(' ', 'alink_space', $word['alink_class']).'alink_check',
                                            'title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),                          
                       'absolute' => true
                       )
*/

          $alink_url[] = l('alink_check\1alink_check',
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check',
                           array(
                           'attributes' =>array('class' => 'alink_check'.str_replace(' ', 'alink_space', $word['alink_class']).'alink_check',
                                            'title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check',
                                                                      'target' => '_blank'),                          
                       'absolute' => true
                       )

#2

danielb - February 4, 2009 - 22:42

Nice work mate - I think that is the optimal solution.

 
 

Drupal is a registered trademark of Dries Buytaert.