Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Chris Star on
I'd like to add a simple target="_blank" attribute to a few menu items.
What module do I need now (sigh) ?
Comments
I don't know of a module
I don't know of a module that does this, but you might want to take a look at these:
http://drupal.org/node/75192
http://drupal.org/node/64892
--
John Forsythe
Blamcast - Custom theme design and more...
Can't figure out a way to to
Can't figure out a way to to it at the module level, but I went for a theme level solution for now...
...however, be aware that this does not rebuild using all options that might be on the link... like fragments and queries, etc.
I was shortsighted. Here is the RIGHT WAY in D6.
Here is the proper way to drop in from link overrides for special circumstances. (In my case target="_blank")
If you want to open ALL
If you want to open ALL external links in a new window you could use $link['external'] to decide if you want to $link['localized_options']['attributes']['target']='_blank';
I did that in menu.inc and it works like a charm with just 3 extra lines of code.
My solution is a bit
My solution is a bit different. You can do something like this:
All external links have and absolute path with the "http:" sting in the url and are opened in a new page.
The internal links have a relative path without the "http:" sting in the url and are opened in the same page.
message only to thank you for
message only to thank you for this code :)
Updated function using theme_menu_item_link() D6
For some reason the code above didn't work for me. I don't have time to check why so I've just recreated the function mixing oriol_e9g's code with theme_menu_item_link() (D6), of course inside template.php:
Menu attributes module
It sounds like the Menu attributes module (http://drupal.org/project/menu_attributes) is exactly what you are looking for, although it is only available for Drupal 6+...
function themename_menu_link_
This worked for me.. !! :-)
~Swarnendu Dutta