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
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