Is there a way to globally set all links off the site to open _blank, or to do so within a area of the site, such as the forums or on all comments?

Comments

trantt’s picture

open _blank from a menu:

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'));
}
else {
return l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array());
}
}

Other than that, I don't have an answer for your question (forum, comment, etc...).

BrendanHodge’s picture

Hmmm. And unfortunately, it's mainly the comments, forums and blogs that I'm trying to do this to. Idea being, that when people post links to outside content, we don't necessarily want to lose them from the main site while they follow that.

trantt’s picture

Can someone help me with version 5 logic? The below logic doesn't work:

function phptemplate_menu_item_link($item, $link_item) {
if (substr($link_item['path'], 0, 4) == 'http')
{
return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description'], 'target' => '_blank') : array('target' => '_blank'), isset($item['query']) ? $item['query'] : NULL);
}
else
{
return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}
}

Here is the warning message that I received:

warning: Cannot modify header information - headers already sent by (output started at /homepages/24/d184208487/htdocs/drupal5/themes/garlandrtl/template.php:1) in /homepages/24/d184208487/htdocs/drupal5/includes/common.inc on line 311.

Thanks

trantt’s picture

can someone please help me with version 5 logic? I would like to add target="_blank" to any url tag where the first 4 characters are http.

Thanks

ekrispin’s picture

The reason why you get the warning message is probably because you have a leading blank line in template.php before the php opening tag.

Eliminate all blank lines outside the ... and it is supposed to work fine...

thehark’s picture

I am doing my first Drupal and thought this was indeed bad but then ... With version 5 I did the following. May not be elegant but seems to work.

I created a block (full html) with the following content

<h2 class="title"> Other Links </h2>
<ul class="menu">
<li class="collapsed"><a href="http://www.somesite.com/pottery-books/roseville-pottery.html" target="_blank">Roseville Books</a></li>
<li class="collapsed"><a href="http://www.anothersite.com/roseville-place/index.php?catid=5" target="_blank">Buy / Sell Roseville</a></li>

</ul>

As I said this may not work for everyone but gets me going.
Oh yes, I am using Bluebreeze. I don't know enough about Drupal to say it will work with all themes.

Richard

trantt’s picture

Currently I'm using the custom block as well but however, there will be time when I need to mix the regular menu item with a _blank type of menu item. As I mentioned before, the new drupal 5 structure is little bit different from the previous version and therefore, I've no idea what to do.

liquidcms’s picture

Yes, i agree.. and just doing some googling now.. but the menu module should have a _blank option with it

also looking at code to see if it is an easily doable patch...

of course the alternative is to create a CCK type with link fields and then use those to create menu items - those fields of course have _blank option

but.. still.. it should be option with menu module

Peter Lindstrom
LiquidCMS - Content Management Solution Experts

trantt’s picture

this module will open an external url from a different tab/browser.