Menu link to open new window
parahumanoid - August 7, 2009 - 21:10
Hello.
I wonder if there is a way to indicate to Drupal that a particular menu item should open in a new window. I don't mind using a solution that makes all external links behave this way.
Thanks for your input.
Alex.

jQuery window.open Click Function
One way that you can go is to use jQuery to have the links open in new windows (assuming you are running Drupal 5 or greater). In your theme, you can use Drupal's add javascript function, drupal_add_js(), and create your own click handler to do this sort of functionality. For example, if you wanted to have all the links in the primary links menu open up in a new window, append the following to your theme's template.php file:
<?phpdrupal_add_js('$(document).ready(function(){
$("ul.primary-links a").click(function(){
window.open(this.href);
return false;
});
});', 'inline', 'footer');
?>
What we are telling jQuery to do is to find all the anchor links in the unordered list that is assigned the primary-links CSS class (the $("ul.primary-links a") part). If you want to target another menu, you would update this to match the appropriate markup for the menu you want this behavior to be on.
*Note: This writeup was written using the DRUPAL-6-13 release to test on
Not quite
Thanks for your response.
I am looking for a method that would allow to handle separate menu items, not the whole menu. It is very important that the solution is more or less admin-level rather than programmer/themer level. I should be surprised if such a mature system as Drupal overlooked this completely. Imagine my mother creating a couple of links in the menu. She shouldn't have to learn JavaScript or PHP. But clicking around in the site's admin section is an acceptable price for this.
Do you have a more layman's suggestion?
Thank you.
Alex.
External Links Filter Module
Just like most things in Drupal, there are many ways to skin the proverbial cat. Take a peek at the External Links Module. There is an option in it to make all the external links in the site open in new windows.
Not working
Hmm,
Weird. I have Garland unmodified and it won't work in it.
It stores the check marks' state but neither displays the shortcut image nor opens links in a new window.
Did it test ok on yours when you used it?
Confused...
I'm still trying to figure
I'm still trying to figure out how Alex's mom learned to build Drupal sites.
Wrong Module Recommendation
No, I didn't test it first and made my recommendation based off of memory of using the module elsewhere. After looking at it more closely, I was mistaken, it does not work for menu items and is only for the nodes themselves. My apologies for sending you down the wrong path! Incidentally, to get the ELF module to work, you need to enable it for each input filter you want it to work on (administer >> site configuration >> input formats ).
Menu Attributes Module
Finally remembered a module that will let you set this: Menu Attributes module. Once it is enabled, it gives you additional menu options including the target attribute (e.g. _blank to open in new window).
Thanks
Sounds great. I'll try it tonight. By the way, my mom is a very smart woman, but she doesn't BUILD sites. I just want her to be able to run one without bothering me all the time with things that ARE beyond her knowledge of the subject.
Thanks for your help. I'll let you know how it went.
Alex.
Thanks again
That was exactly what I was looking for. Thanks for the tip.
Alex.
thanks from me too
...gotta love the community:
--> problem
--> drupal.org search
--> helpful suggestions
--> fix problem, get on with project