Log in

View Full Version : BB Code Enhancements - Open local links in same window; external links in new window


djbaxter
07-27-2012, 10:00 PM
By default, vBulletin opens all links in posts in a new window (target="_blank").

This mod opens local links (i.e., links from your domain) in the same window (target="_self"), and external links in a new window or tab (target="_blank").

INSTRUCTIONS:

AdminCP >> Style Manager >> Common Templates >> headinclude

FIND in headinclude (this is where I added the code but probably anywhere would work):

<vb:if condition="$stylevar['favicon']">
<link rel="Shortcut Icon" href="{vb:stylevar favicon}" type="image/x-icon" />
</vb:if>


ADD AFTER:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a[href^=http]").each(function(){
if(this.href.indexOf(location.hostname) == -1) {
$(this).attr('target','_blank');
}else{
$(this).attr('target','_self');
}
})
});
</script>


Save. Done. :)

Thanks to my son, Wilder Tweedale (http://www.wildertweedale.com), for assistance with the code.

Update:

VB4 uses jquery on only a few pages. Yahoo YUI is the default library on all pages.

BOP5 has just published a javascript version of this as a product, which may be easier for many to implement and which avoids possible increases in page load times.

See http://www.qapla.com/mods/misc.php?do=producthelp&pid=intextlinkingbop5

djbaxter
07-28-2012, 12:22 PM
Before someone asks the obvious question...

Q: How is this mod different from the mod by SweCastel (https://vborg.vbsupport.ru/member.php?u=411400) https://vborg.vbsupport.ru/showthread.php?t=256195?

A: SweCastel (https://vborg.vbsupport.ru/member.php?u=411400)'s mod requires editing one of the core vBulletin files. I dislike doing that because it means re-editing the file with every update. The current mod requires template edits only.

BirdOPrey5
07-28-2012, 08:23 PM
This is a great idea, I use a custom BBCode for local links on my forum but it's annoying to have to worry about which are local and which aren't.

I would just give a heads up to people if they are already loading jquery on their pages they don't need to load it twice- actually 2 different jquery versions may conflict.

djbaxter
07-28-2012, 10:58 PM
This is a great idea, I use a custom BBCode for local links on my forum but it's annoying to have to worry about which are local and which aren't.

Thanks. :)

I would just give a heads up to people if they are already loading jquery on their pages they don't need to load it twice- actually 2 different jquery versions may conflict.

To be honest, I thought it was loaded in native vBulletin installations but couldn't get the script to work without the load line added.

BirdOPrey5
07-28-2012, 11:51 PM
VB4 uses jquery on only a few pages. Yahoo YUI is the default library on all pages.

djbaxter
08-04-2012, 12:07 PM
VB4 uses jquery on only a few pages. Yahoo YUI is the default library on all pages.

BOP5 has just published a javascript version of this as a product, which may be easier for many to implement and which avoids possible increases in page load times.

See http://www.qapla.com/mods/misc.php?do=producthelp&pid=intextlinkingbop5

BirdOPrey5
08-04-2012, 08:21 PM
I didn't want to release my own here since if it wasn't for yours I wouldn't have thought to do it. ;)

djbaxter
08-04-2012, 08:48 PM
Well, suffice it to say that I'm now using yours. :)

And I wouldn't be offended in the slightest if you re-released your mod here.

BirdOPrey5
08-05-2012, 01:29 PM
Thanks. I put it up here: https://vborg.vbsupport.ru/showthread.php?t=286348 :up:

djbaxter
08-05-2012, 01:39 PM
Excellent... To others, I'm now using the BOP5 mod on four vB4 forums... highly recommended.