Page 1 of 1

Open links in new tabs

Posted: 08 Mar 2010, 13:41
by alphahusky
I made two mods. Open links in new tab bbcode and open links in new tab non-bbcode. I went to reference them today, and they're gone... AHHHH! Help!
I even had to re-register.. aye aye aye! 8-) :o

Re: Open links in new tabs

Posted: 08 Mar 2010, 13:57
by Stoker
Found some of it here:
Alphahusky » 06 Jun 2009, 02:31 wrote:I know there is a post already about opening links in a new tab, but is is only for the URL bbcode and does not work if someone just types in the the web address without the URL bbcode...

This way will will open links in new tabs without the url bbcode....

(!!PLEASE SEE NEXT POST BEFORE USING THIS CODE. YOU MAY WANT TO USE THE NEXT SET INSTEAD.!! Thank you!)

Open: /includes/functions_content.php
Find:

Code: Select all

$html	= "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";
Replace with:

Code: Select all

$html	= "$whitespace<!-- $tag --><a$class href=\"$url\" onclick=\"window.open(this.href);return false;\">$text</a><!-- $tag -->$append";
You may need to Purge the cache after doing this....

That's it!
Alphahusky » 06 Jun 2009, 02:50 wrote:Oops... Found a couple of hiccups...

1. Email link opens new tab
2. local links are opened in new tab as well...

I just fixed them though....

I will leave the code above unchanged in case people want it that way.. elsewise, here is the fixed code that will only open external links in new tabs and leave local links and email alone..

Find:

Code: Select all

$html   = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";
Or find (If you used my above code first)

Code: Select all

$html   = "$whitespace<!-- $tag --><a$class href=\"$url\" onclick=\"window.open(this.href);return false;\">$text</a><!-- $tag -->$append";
Replace with:

Code: Select all

$DoNormal = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append"; 
	
        if ($type == MAGIC_URL_EMAIL)
        {
            $html    = $DoNormal;
        }
		elseif ($type == MAGIC_URL_LOCAL)
		{
			$html    = $DoNormal;
		}
        else 
        {
            $html    = "$whitespace<!-- $tag --><a$class href=\"$url\" onclick=\"window.open(this.href);return false;\">$text</a><!-- $tag -->$append";
        }
and there is a Link in new window bbcode somewhere in the db here.