click menu item -> open link in new window?
winman1 - July 24, 2006 - 04:20
hi all,
i need an menu item which links to external website,
and need this behaviour: if user click into this menu item,
the extrenal web is oppened but in new window ( add somewhere
target=_new ?)
so my Drupal site is still open in used.
Many thx for advice.

Use Block instead of node
winman1,
check this test website out, is this what you are looking for?
http://www.test.icevn.org
onder left navigation bar, and under VCSA Chapter, click on either Dallas, Washington, etc...
Here what I did
1. go to admin/block
2. Click on Add Block tab to create a new block
3. Under block body, I did the followings:
a href="http://www.vhkhvn.org/austin" target="_blank">Austin< /a>
a href="http://www.vanhoakhoahoc.org/dfw/" target="_blank">Dallas< /a>
a href="http://www.vhkhvn.org/vcsatoronto" target="_blank">Toronto< /a>
a href="http://vcsa-dc.org/" target="_blank">Washington D.C.< /a>
(please add lesser than site (shift and comma) at the begining of each line)
4. Save you block
5. Now you can enable your block
That's it. Hope this is what you are looking for
thx Trần a lot. I'm total
thx Trần a lot.
I'm total newbie in Drupal, but i see this system is so slight and wellconfigured!
Drupal in Vietnamese?
hi anh Trần and others,
do you know any vietnamese version of Drupal 4.7.2?
Or at least could you tell me how/where I can transtale some phrase
"Read More" into my native language - Vietnamese?
Thx a lot.
Drupal in Vietnamese?
Winman1,
If you found one, please let me know as well. I think we should divide the task among ourself and get it done ourself. Anyway, please contact vibien at gmail.com I think he/she might be able to help us on this matter. Also, are you using i18n module?
hi anh Trần, i found such
hi anh Trần,
i found such solution:
administer->localization->add language .... Vietnamese
then set default lang as Vietnamese and do EXPORT for vn lang,
you will get vi.po file, our task is edit vi.po file, and then IMPORT
vi.po file back for vn lang.
The problem i have is in vi.po file i must add special html char code
for ê char, or it will have strange display for "Xem thêm" (read more).
I will do this via MS frontpage in order to get html code for ê char.
Hope vibien at gmail.com has same solution? has he already translated
vi.po file?
PO editor
winman1,
a good text editor or a po editor (you can get one for free through google search) should handle utf-8 as well. If wanted, we can divide this task evenly among us. Regarding to vibien, I think I will contact him sometime today. It doesn't hurt to check him out...
Also, you are welcome to contact me through my email, just click on my user name and it will take you there...
Trần, it's nice to have
Trần,
it's nice to have vi.po file already translated,
but I am now so busy to work in this f***** country
to make few vnd!!!!
Stay freely outside and never come back to vn like me .... big mistake.
best regards
drupal theme
winman1,
do you know how to create a Drupal theme? I'm supporting several non-profit organizations and they don't have that much money to spend... Also, are you serious about making VND? Where are you right now? Can you send me an email so we can discuss more about it....
Thansk
chào các bạn
:p vui ghê, mãi đến giờ mới có một nhóm người việt nói chuyện với nhau trong đây. vibien khg chuyên ngành IT nên đã khg còn đụng chạm nhiều đến drupal sau khi đã khg còn cần và khg chuyên xử dụng nó nữa. sorry khg giúp đỡ được gì nhé (indeed, no time too). by the way - I'm a female :p not male.
vibien
ps.: thx Hung for linking me to this threat
Xin loi nha vibien
Mi`nh xin loi vi` khong biet ba.n la` female... sorry.......
Vibien co' bie^'t nhung nguoi VN kh'ac du`ng drupal khon^ng?
Thanks
khg co chi dau H.
trang xử dụng drupal và bản copy vi.po từ đây ra, các bạn thử vào liên lạc trực tiếp và hỏi xem sao
http://www.vnlinux.org/sitemoi/index.php?q=node/23
thân mến
vibien
Open external link in new window (naughty naughty!!!!)
When people open a new link from my site, I want to keep my site open in the background. What a pig, eh? So, in the includes directory, about line 1090 in common.inc, I replaced
return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'>'. ($html ? $text : check_plain($text)) .'</a>';with
if(substr($path,0,4)=="http"){return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) . 'target=\"_blank\">'. ($html ? $text : check_plain($text)) .'</a>';
}
else{
return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'>'. ($html ? $text : check_plain($text)) .'</a>';
}
When "http" are the first four characters in the menu item URI, the link is automatically opened in a new window.
Chris Brown
drupal feature
Chris,
I'll give it a try. This is much better than what I did... Anyway, instead of overwritten common.inc, I think drupal should handle this feature automatically (build in property)
Thanks
Built in
I agree! Hacks are a temporary solution! Also - to be correct, the if statement should be based on the item's "absolute" property rather than the $path string, because ftp or https, etc need to be covered, and because that would be more consistent with the approach of the existing code.
Check out the Mooney's Bay Webcam, at http://liquidvisual.ca
It's better like this, without escaping quotes
if(substr($path,0,4)=="http"){return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) . 'target="_blank">'. ($html ? $text : check_plain($text)) .'</a>';
}
else{
return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'>'. ($html ? $text : check_plain($text)) .'</a>';
}
Don't hack core!
You should add something like this this to your template.php file instead although it's still not a totally clean solution.
<?phpfunction 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());
}
}
?>
--
Rob
Founder and Director
Electronic Insight Corporation
Recent Drupal Projects: MP3PIG | MySpace Layouts
Hacks are like affairs
Thank you Prince Rob. If I knew anything at all I would be suggesting a "New Window?" checkbox in menu item edit, but there is too much to coordinate in creating that for my knowledge of Drupal. Besides, assuming a new window runs contrary to many peoples' notions of etiquette, although not my own when it communicates "You are leaving my site," just as I do not automatically hang up the phone if the other party talks to a person at the other end. It depends on context.
Hacks, because there is no way of doing them properly, give a wonderful freedom until they come crashing down on you.
How to use template.php
Rob,
Is this supposed to be a new text file? For some reason, I couldn't able to locate it in my local directory. If this is a new file, can you show me where to put this file and how to reference it in my code? Sorry for all of this question. I don't know anything about PHP or drupal architecture.
Thanks
here you go
some reading about template.php files and their purpose in life.
http://drupal.org/node/11811
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
RSS link
is it possible to launch a new browser/tab from an RSS link? I implemented phptemplate_menu_item_link but it doesn't work for the RSS link
Thanks
Variation Needed
Setting target windows is nice if we already have the window or frame set up the way we want it, but when a new
_blankwindow is created it contains all the dressing (location bar, status, blah blah woof woof) the parent has; and you may have seen some browsers have more real estate dedicated to various buttons and trimming than actual content.onlickhas been part of the HTML spec since 4 I think and it can be used in an anchor tag to open a new window and be able to control what window dressing is visible. At least I've seen it work most places I've looked (not extensively), but the W3 does issue a caveat. And if JavaScript is turned off, it doesn't work, but I am willing to live with that for now as I will have another object to fall back on.What I want to do is what I have here. A page with text and links that open panoramas in a new window: maximum photo/pano, minimum browser clutter. See the first row of links called "New Style Link".
How can I adapt your potentially very useful function to use the
onclickattribute instead of, or in addition to, thetargetattribute?The HTML I used at the above link is this: (indented for readablility, my first post had the line too long)
<?php<a href="YHG/FS3.html"
title="Open This Full Screen Panorama in a New Window"
onclick="MyWindow=window.open('YHG/FS3.html','FullScreen','toolbar=no,location=no,
directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
return false;">Full Screen</a>
?>
At the moment if they have JavaScript off they see nothing. I am trying to move some of the design and ideas from what I have now (static pages) to Drupal.
Here is a clumsy and hard coded (non PHP database calling) line that attempt to isolate where I have to begin modifying it.
<?php
return l($item['title'], $link_item['path'], isset($item['description']) ?
array('title' => $item['description'],
'onclick' => 'MyWindow=window.open(\'ma/\',\'FullScreen\',\'toolbar=no,location=no,
directories=no,status=no,menubar=no,
scrollbars=yes,resizable=yes\'); return false;') :
array('target' => 'MyWindow=window.open(\'YHG/FS3.html\',\'FullScreen\',\'toolbar=no,
location=no,directories=no,status=no,menubar=no,
scrollbars=yes,resizable=yes\'); return false;'));
?>
(There are so many parameters to pass that I don't mind hard coded in the function that it's too long of a line so I tried to break it up, sorry if it's harder to read.)
I would love to know if I'm on the right track, is this how I go about it.
I would also love to know what tidbit to put in place of the hard coded paths.
Many TIA
-Drew
ps. after reading the above comments many times...I do not want every http link on my site to open a new window, but I want selected links to. Is there an easy work-around instead of having to write a full-blown situation that writes all those window.open parameters to a table? and writing code to let people set those features and such. For now I'd love a simple solution to get me up and running, later when I can coast I can revisit this stuff and try to do it the right way.
Rob, I like this way of
Rob,
I like this way of doing it on the theme level.
I tried this and it seems to be working well, although, for some reason it doesn't work for my primary links. Any idea how I could get that to work?
Thanks!
By no means am I a great PHP
By no means am I a great PHP programmer, but I was looking for a solution that edited the primary links as well. I did a little hack which seems to work fine. Please improve upon it if you can =)
So in the page.tpl.php file of my theme, right above/before the:
print theme('links', $primary_links, array('class' => 'links primary_menu'))
I added:
foreach ($primary_links as $key=>$value){ if (substr($primary_links["$key"]["href"], 0, 4) == 'http')
{
$primary_links["$key"]["attributes"]["target"] = "_blank";
}
}
Thanks! I will give it a
Thanks! I will give it a try.
Will this open ALL primary links in a new window? Think it's possible to specify which ones should and which ones shouldn't open in a new window?
Will give it a try, and advise anyways.
Cheers
Perfect solution...
You helped me a lot with this!!!!
Thank you!
Not in 4.7
The above code is not pertinent to Drupal 4.7, which is the version this thread was started about. The format of $primary_links changed between 4.7 and 5.x. (I'm learning this the hard way, as I tried to implement the above logic unsuccessfully in 4.7.)
...
OK, below is what worked for me in 4.7. It took a LONG time for me to realize that, in 4.7, $primary_links is an associative array in which the index is some internal string like "menu-1-3" and that the value is the complete markup for the link. I couldn't find this fact documented anywhere. Anyway, my approach is to insert the target attribute into that value string. In PHP 4, you can't use "foreach" because you can't pass the value by reference (in PHP 5 you can prepend an ampersand and make it writable). So I learned how to use "each" along with "list", which gives you both the values and their associated indexes, permitting you to write back to he original $primary_links array.
In place of this (in the page template file):
<?php if (isset($primary_links)) { ?><div id="primary"><?php print theme('links', $primary_links) ?></div><?php } ?>...I put this instead:
<?phpif (isset($primary_links)) {
print ('<div id="primary">');
reset($primary_links);
while (list($key, $value) = each($primary_links)) {
if (strpos($value, 'http:') !== false) {
$x = strpos($value, '>');
if ($x !== false) {
$primary_links[$key] = substr_replace($value, ' target="_blank"', $x, 0);
}
}
}
print theme('links', $primary_links) . '</div>';
}
?>
Note that I prefer to use PHP print statements rather than constantly turning PHP "on" and "off" and intermixing the HTML that way. Note also that I check for the colon too ("
http:"), and not just "http", to cover the slim chance that a local URL might have "http" within it. Finally, you can't check for "http" at the specific index of 0 (zero) in Drupal 4.7 because the string value actually starts with "<a".Hope this helps somebody!
Nice solution sisconda
I'd like to do this with the other menu's as well ($sidebar_left for example), however it appears that the way they are generated is different then the primary menu. http://drupal.org/node/145316 I'm going to see if I can come up with anything however if anyone has ideas of using sisconda's code for other menu items let me know.
this worked
Thanks very much. this solution worked.
subscribing
subscribing
Perfect!
Perfect!
Thank you, RobRoy I'm
Thank you, RobRoy
I'm looking for this solution
Is it possible to do something similar using hook_link?
I don't really know where you use hook_link, but if I wanted to change links that appear in menus on certain pages to open in new windows, could I use hook_link for that instead of the phptemplate modification suggested above?
used this! works great! thx!
used this!
works great! thx!
They need to have it an
They need to have it an option (perhaps a checkbox on the menu item settings page?) in Drupal without needing to modify anything.
Honestly I'm not a big fan of how Drupal implements the menu. But I guess we are all entitled to our opinions!
Option to lauch an external url from a new browser
"They need to have it an option (perhaps a checkbox on the menu item settings page?) in Drupal without needing to modify anything."
>> I am totally agree with this. Launching an RSS link should be the same.
Javascript solution
In your template.php add:
drupal_add_js('misc/newwindow.js', 'theme');Then in drupal_install/misc/newwindow.js add:
$(function() {$('a[@href^=http]').not('[@href*=yourdomainname.com]')
.addClass('external-link')
.click(function() {
window.open(this.href, '_blank');
return false;
});
});
Change 'yourdomainname.com' to your website's domain name, now any http prefaced links not from that domain will open in a new window.
http://drupal.org/node/105248#comment-234291
Working fine
The solution posted by krikit is working fine. Thanks for the solution.
WORKS LIKE A CHARM
Thanks for this brilliant, fast loading, javascript for my site. Works great, double recommend it!
My newbie solution.
I found the advice here great, so I added this functionto my .theme file to switch out links via the theme :
function theme_menu_item_link($item, $link_item) {
return l($item['title'], $link_item['path'], !empty($item['description']) ? ((substr($link_item['path'], 0, 4) == 'http')? array('title' => $item['description'], 'target' => "_blank") : array('title' => $item['description'])) : array(), isset($item['query']) ? $item['query'] : NULL);
}
This seems to work well on any external url.
Considering an external link will be detected in the string in this manner, using a "|" in the string and parsing the string to figure a target might be a quick and dirty workaround for multiple targets. For example, "http://www.example.com|_blank" could be parsed.
Just a thought.(I'm still getting used to drupal.)
For 5.x use ExtLink
The External Link module seems to do exactly what we all want, though it's only for 5.x
http://drupal.org/project/extlink
-P
open flickr in new window
Hi,
How to open my Flickr photosets in new window.
Currently i enabled this block on my right side bar, when user clicks on this it has to open in a new browser window.
Need Help !!!
I have the same problem
Need someone else's wings to lift me up...Ho can I add a "_blank" target to a link set in a module menu hook(?) in the modulesname_menu() function which lists menu by returning the $items.
Thanks a lot in advance.
---------------------------------
I am like a new-born bird trying to fly but couldn't do so...
I'm still looking trying to
I'm still trying to figure out how I add a target="_blank" to one of my primary links. Any help would be appreciated.
Thanks Sisconda
Ur code is working absolutely...
Thanks!!!
target=_blank in primary links menu
Check out the solution(s) at Open link in new window.
Source for properties in downtown Toronto
Toronto Lofts - For a List of the best condo units available for sale, visit us!