MyBB Community Forums

Full Version: Open External Links in New Window?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to make external links open in a new window?
Change doshorturl inside of inc/functions_post.php. In MyBB 1.1.2 (the most recent version), all links are targeted to _blank. If you only want external links to open new windows, you have to parse_url paying attention to the host portion of the result.
Wow. I appreciate your help, but I'm not sure what you're referring to. I'm quite rusty on my programming. I found this, but what do I change?

function doshorturl($url, $name="")
{
	$fullurl = $url;
	// attempt to make a bit of sense out of their url if they dont type it properly
	if(strpos($url, "www.") === 0)
	{
		$fullurl = "http://".$fullurl;
	}
	if(strpos($url, "ftp.") === 0)
	{
		$fullurl = "ftp://".$fullurl;
	}
    if(strpos($fullurl, "://") === false)
    {
        $fullurl = "http://".$fullurl;
    }
	if(!$name)
	{
		$name = $url;
	}
	$name = stripslashes($name);
	$url = stripslashes($url);
	$fullurl = stripslashes($fullurl);
	if($name == $url)
	{
		if(strlen($url) > 55)
		{
			$name = substr($url, 0, 40)."...".substr($url, -10);
		}
	}
	$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";
	return $link;
}
By default any link in any posted in mybb opens in a new window.
However if we understood you right and you want only external links to open in a new window. then try this

above
$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";
 

add

if(strstr($fullurl,$mybb->settings['bburl']))
			{
				$target = "_self";
			} else {
				$target = "_blank";
			} 
now change target=\"_blank\" to target=\"$target\"


regards
zaher1988 Wrote:By default any link in any posted in mybb opens in a new window.

Yes, it appears that links posted on the site open externally, which is fine.

I only want to add the external links section of the forum to open in a new window. I'm referring to the links that look like forums, but take you to another page when you click them.
Aha then you want the forum that has external link to load in a new window!! ok.
open ./index.php

find

$threads = "-";
					}
					else
					{
						$posts = mynumberformat($forum['posts']); 

replace with

$threads = "-";
						$target = "_blank";
					}
					else
					{
						$target = "_self";
						$posts = mynumberformat($forum['posts']); 

Now in the Admin CP >Templates > Modify / Delete > Expand > Forumbit templates > forumbit_depth2_forum

find
 <a href="forumdisplay.php?fid=$forum[fid]">

replace with
<a href="forumdisplay.php?fid=$forum[fid]" target="$target"> 

regards
Works perfectly, thanks!
Ok, one more... What about Subforums that link externally? I imagine the above code would work with small modifications.
I guess you will only need to do what you have dont to the forumbit_depth2_forum template but this time edit forumbit_depth3

regards
(2006-05-24, 06:53 PM)zaher1988 Wrote: [ -> ]Aha then you want the forum that has external link to load in a new window!! ok.
open ./index.php

find

$threads = "-";
					}
					else
					{
						$posts = mynumberformat($forum['posts']); 

replace with

$threads = "-";
						$target = "_blank";
					}
					else
					{
						$target = "_self";
						$posts = mynumberformat($forum['posts']); 

Now in the Admin CP >Templates > Modify / Delete > Expand > Forumbit templates > forumbit_depth2_forum

find
 <a href="forumdisplay.php?fid=$forum[fid]">

replace with
<a href="forumdisplay.php?fid=$forum[fid]" target="$target"> 

regards

I can't find this code in index.php...