Download & Extend

Navigation menu with target="_blank"?

Project:Drupal core
Version:6.x-dev
Component:menu system
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

how can i add a target="_blank" to the go/test link in my Navigation menu (and Primary/Secondary Links), if this link is redirecting to an external site? If this is possible this should be a configurable per go-URL option...

Any idea?

Comments

#1

I don't think this is an issue for the Go two module, it handles target=_blank just fine. The primary and secondary links, however, don't have an option for them.

I think this issue needs to be moved over to the menu module/core

#2

Project:Go - url redirects» Drupal core
Version:4.7.x-1.x-dev» 4.7.4
Component:Code» menu system

ok

#3

Version:4.7.4» x.y.z

new features go into devel version.

#4

Version:x.y.z» 4.7.4

Put this in your template.php

<?php
function phptemplate_menu_item_link($item, $link_item) {
    if (
substr($link_item['path'], 0, 4) == 'http') {
        return
l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description'], 'target' => '_blank') : array('target' => '_blank'));
    }elseif (
stripos($link_item['path'], '_blank') > 0){
       
$link_item['path'] = str_replace('_blank','',$link_item['path']);
        return
l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description'], 'target' => '_blank') : array('target' => '_blank'));
    }else {
        return
l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array());
    }
}
?>

Explaination: Filters all external links (starting with http), and links where path contains _blank and add target="_blank" property.
Just add _blank to the path of the node and you're ok.

Thanks to trantt for his post.

Regards.

Maatwerk in webapplicaties

#5

Version:4.7.4» 4.7.x-dev

killes was right, but let's set it to 4.7.x-dev.

Is this fixed? If so, please close the issue.

#6

Version:4.7.x-dev» 6.x-dev
Status:active» closed (duplicate)

Duplicate of http://drupal.org/node/102669

#7

can someone help us with version 5 syntax? return l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description'], 'target' => '_blank') : array('target' => '_blank')); is not working on version 5

#8

Did you try 'target' => 'blank' or in other words taking out the underscore? That works for me in D5. For a more thorough look at this problem take a look at my post here about it http://www.nowarninglabel.com/home/node/13

#9