Ewen's Files

jQuery Link Manager Plugin

This jQuery plugin manages the opening of links in new windows (or any other possible value of the anchor target attribute) removing the need for the target attribute (e.g. target="_blank" for opening in a new window) which is deprecated in XHTML strict standards.

By default this plugin will open all external links in a new window. Using the available options you can include internal links using the 'include' option; exclude external links using the 'exclude' option, choose which part of the link's href attribute to match (domain, pathname, querystring and hash) and define what the link should target (_blank by default.)

Leave any comments below or on the plugin's jQuery page, or contact me here.

API

selector : 'a:not([href=#])' ($.linkManager.defaults.selector)
Which links to select.
target : '_blank' ($.linkManager.defaults.target)
Where to open the link.
include : [] ($.linkManager.defaults.include)
Array of keywords to match in each internal link for inclusion in the open in new window rule.
exclude : [] ($.linkManager.defaults.exclude)
Array of keywords to match in each link (internal or external) for exlusion in the open in new window rule.
useDomain : true ($.linkManager.defaults.useDomain)
Whether or not the include/exclude options should search the domain part of the URL (http://www.example.com/path/file.html?querystring=true#hash)
usePathname : true ($.linkManager.defaults.usePathname)
Whether or not the include/exclude options should search the pathname part of the URL (http://www.example.com/path/file.html?querystring=true#hash)
useQuerystring : true ($.linkManager.defaults.useQuerystring)
Whether or not the include/exclude options should search the querystring part of the URL (http://www.example.com/path/file.html?querystring=true#hash)
useHash : false ($.linkManager.defaults.useHash)
Whether or not the include/exclude options should search the hash part of the URL (http://www.example.com/path/file.html?querystring=true#hash)

Examples

This is an awkward plugin to demonstrate because of the examples directing you away from this page, but it's worth the hassle (:

Example one

$('#example-one').linkManager();

Example two

$('#example-two').linkManager
({
    include : ['.pdf', '.doc']
});

Example three

$('#example-three').linkManager
({
    include : ['.pdf', '.doc'],
    exclude : ['example']
});

Example four

$('#example-four').linkManager
({
    include : ['.pdf', '.doc'],
    exclude : ['example'],
    useDomain : false
});

Example five

$('#example-five').linkManager
({
    include : ['.pdf', '.doc'],
    exclude : ['example'],
    useDomain : false,
    usePathname : false
});

Example six

$('#example-six').linkManager
({
    include : ['.pdf', '.doc'],
    exclude : ['example'],
    useDomain : false,
    usePathname : false,
    useQuerystring : false
});

Example seven

$('#example-seven').linkManager
({
    selector : 'a:not([href*=example]):not([href=#])'
});

Like my Stuff?

All the stuff I create and host on this site is free for personal and commercial use unless otherwise stated.

If you find a use for any of it and would like to show your appreciation you can send me a donation via PayPal.

Also it would be great if you could like, +1 or tweet any of the projects that you use.

Cheers, Ewen

Project Information

Name
Link Manager
Date Created
Saturday 2nd July 2011
Description
This jQuery plugin manages the opening of links in new windows (or any other possible value of the anchor target attribute) removing the need for the target attribute which is depr…
Project Resources

Latest Projects

Project
PHP Character Converter
Date Created
Sunday 2nd October 2011
Description
Using a conversion library this class can convert the characters in a string, for example using the NATO Phonetics library, a string containing 'test' would be returned as 'tango e…
Project
jQuery Style File Input
Date Created
Sunday 25th September 2011
Description
The Style File Input jQuery plugin provides a method for displaying a styled file input. It creates several extra elements in the DOM which can be freely styled in almost any way.