Hi Drupal developers,

How can I set one of my primary links to be opened in a new tab or new window? This case can be extended to all menu items, so the menu module may be developed to add a custom setting to each menu item to specify how to be opened?

Your kindly response is appreciated.

Comments

dnewkerk’s picture

Off-hand I'm not sure how to do it... I wanted to let you know though that, unless its a client demanding this feature or you have a special/necessary reason for it, I'd suggest that you do not do it. Currently on the web its considered bad etiquette for a site to open new windows when users click links/menus.

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

rezvani63’s picture

Thanks David, but sometimes you need to direct one special link to a new tab. In my case I have a link among my primary links that my customer asked me to be opened in a separate tab. So I have to perform his request. So what is the best solution?

iyan’s picture

You could refer to the discussion on this link: http://drupal.org/node/260104

dccrane’s picture

Bad web etiquette? That seems odd. The reverse seems more true in the case of Drupal. What if the link takes the visitor away from a Drupal-formatted page with the menus visible? That forces the visitor to use the back button to get back to those menus when simply closing the new page would be much easier and, for me at least, more logical. Or, if desired, s/he can switch back to the Drupal page and open another link.

"Etiquette" seems a poor substitute for allowing existing functions to operate as designed.

sagarniwas’s picture

add following jquery code to your page.tpl.php file in head area
provided that jquery must be run on your machin.

$(document).ready(function(){ $('#id').children(":first").attr("target", "_blank"); });

where #id is your li tag id

sagarniwas’s picture

Opening a primary link in a new tab or window (_blank):-

add following jquery code to your page.tpl.php file in head area
provided that jquery must be run on your machin.

$(document).ready(function(){ $('#id').children(":first").attr("target", "_blank"); });

where #id is your li tag id

sagar bhoir
+919892265793

Anandyrh’s picture

Hi All,

I have been asked from my client to do the same... and It's very bad etiquette for keeping menus so strict. I am sure many of us are facing this issue. as a developer i feel discomfort with these rules.

adding the following jquery code to your page.tpl.php file in head area might solve issue for one time.

$(document).ready(function(){

$('#id').children(":first").attr("target", "_blank");
});

But i think there must be a better way to make these things user friendly for developers. as always the requirements are dependent on the client.

I am in a journey to find better way... help me

devtherock’s picture

If you are ok with Jquery its fine, otherwise you can try this module: http://drupal.org/project/menu_attributes

Thanks

regards
Dev/Kuldev

Anandyrh’s picture

Hi Devtherock,

this is really a great module... i have tried it on dev site looks awesome.

lovedrupal6’s picture

http://drupal.org/project/extlink

For all those who are still looking - the above module is what you need

rta’s picture

add the target attribute to the l() function:

<?php
l($node->title, 'node/' . $node->nid, array('attributes' => array('target' => '_blank')));
?>