PDA

View Full Version : external links target=_blank, internal links target=_top?


dacho
02-25-2010, 01:57 PM
The default behavior in vBulletin is that when someone posts a URL vBulletin converts it to a clickable link and adds target=_blank. This is great for when people post links to other websites, etc. so that my forum stays open in the background.

But when people post internal links to other threads, it can get annoying for them to open in a new window.

Is there any way I could create an "if else" logic that would:
-add target="_blank" when creating autolinks to any external url
-except add target="_top" when creating autolinks to mydomain.com/forum threads?

(I guess the if else logic would actually work the other way around, if the URL=myurl, vBulletin would add target="_top", else it would add "target="_blank".

How would I do this exactly?
The question originally asked by Boatdesign for VB3 (https://vborg.vbsupport.ru/showthread.php?t=33753&highlight=target)

Lynne
03-23-2010, 01:44 PM
You might be able to try a str_replace for links in messages:

$find = '<a href="http://';
$replace = '<a target="_blank" href="http://';
$this->post['message'] = str_replace($find, $replace, $this->post['message']);

$find = '<a target="_blank" href="http://www.yoursite.com';
$replace = '<a target="_top" href="http://www.yoursite.com';
$this->post['message'] = str_replace($find, $replace, $this->post['message']);

I don't like it, but maybe it will give you an idea to go about it another way.