Back to vBulletin 4.x Template Modifications

Open local links in same window; external links in new window
Mod Version: 1.00, by djbaxter

vB Version: 4.2.0 Rating: (2 votes - 5.00 average) Installs: 21
Released: 28 Jul 2012 Last Update: Never Downloads: 42
Not Supported Template Edits Re-usable Code  

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

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

PHP Code:
<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, http://www.wildertweedale.com, for assistance with the code.

Update:

Quote by BirdOPrey5
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

Download

File Type: %1$s Open internal links same window external links new window.txt (600 Bytes, 42 downloads)

Similar Mods

Mini Mods Open Local links in same window, External in new window vBulletin 4.x Add-ons
Mini Mods Same Window For Local Links vBulletin 3.6 Add-ons

vblts.ru supports vBulletin®, 2022-2024