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.

Comments

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:

<?php
drupal_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

Puzzled_blank

Sound like what I'm looking for. I got the Menu Attributes module, enabled Target attribute and selected New Window (_blank), but I'm unclear what to do next. If I add anything to the end of the Menu Item Path like Target_blank, I get a 404 error. Sorry for the dumb question, but . . .

Wesley

To finish your feature...

- Go to your menu administration page
- Click "Edit" for your specific menu item
- At the bottom on that configuration page, look for a "Menu Item attributes" field group
- Expand that, then select the details for whatever opens you enabled within the Menu Attributes module settings.

HTH!

Thanks

Thank you. That was really helpful.

Not quite working...

I know this is a long time out (as this is in reference to the first response to this post in 2009), but I just tried adding the code from that first comment into my template and with a little configuring it is working almost as I'd like it. Here's my question...
With this code I'm getting a new window opening in another tab. I know it's reading the javascript as I also built in a move of the window:

drupal_add_js('$(document).ready(function(){
                   $("div.view-content a").click(function(){
                     top.consoleRef=window.open(this.href);
                     consoleRef.moveBy(40,0);
                     return false;
                     });
                   });', 'inline', 'footer');

Now I know that my browser is set to open new windows in tabs, but I have code like this built into a non-drupal site I have and it opens up a floating window (a brand new browser window - not just a tab) with the javascript.

Is this possible with this approach?

RE: Menu Attributes Module Posted by m1mic

GREAT STUFF....
Been looking for this all day long.... it does exactly what i need it to do, unlike the external links module, etc etc

nobody click here