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();
- http://www.example.com/new
- http://www.example.com/example.htmlnew
- http://www.example.com?example=truenew
- http://www.jainaewen.com/files/javascript/jquery/linkManager/#example-onesame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/fileone.pdfsame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/index.html?query=fileone.pdf#example-onesame
- #ignored
Example two
$('#example-two').linkManager
({
include : ['.pdf', '.doc']
});
- http://www.example.com/new
- http://www.example.com/example.htmlnew
- http://www.example.com?example=truenew
- http://www.jainaewen.com/files/javascript/jquery/linkManager/#example-twosame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/fileone.pdfnew
- http://www.jainaewen.com/files/javascript/jquery/linkManager/index.html?query=fileone.pdf#example-twonew
- #ignored
Example three
$('#example-three').linkManager
({
include : ['.pdf', '.doc'],
exclude : ['example']
});
- http://www.example.com/same
- http://www.example.com/example.htmlsame
- http://www.example.com?example=truesame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/#example-threesame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/fileone.pdfnew
- http://www.jainaewen.com/files/javascript/jquery/linkManager/index.html?query=fileone.pdf#example-threenew
- #ignored
Example four
$('#example-four').linkManager
({
include : ['.pdf', '.doc'],
exclude : ['example'],
useDomain : false
});
- http://www.example.com/new
- http://www.example.com/example.htmlsame
- http://www.example.com?example=truesame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/#example-foursame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/fileone.pdfnew
- http://www.jainaewen.com/files/javascript/jquery/linkManager/index.html?query=fileone.pdf#example-fournew
- #ignored
Example five
$('#example-five').linkManager
({
include : ['.pdf', '.doc'],
exclude : ['example'],
useDomain : false,
usePathname : false
});
- http://www.example.com/new
- http://www.example.com/example.htmlnew
- http://www.example.com?example=truesame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/#example-fivesame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/fileone.pdfsame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/index.html?query=fileone.pdf#example-fivenew
- #ignored
Example six
$('#example-six').linkManager
({
include : ['.pdf', '.doc'],
exclude : ['example'],
useDomain : false,
usePathname : false,
useQuerystring : false
});
- http://www.example.com/new
- http://www.example.com/example.htmlnew
- http://www.example.com?example=truenew
- http://www.jainaewen.com/files/javascript/jquery/linkManager/#example-sixsame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/fileone.pdfsame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/index.html?query=fileone.pdf#example-sixsame
- #ignored
Example seven
$('#example-seven').linkManager
({
selector : 'a:not([href*=example]):not([href=#])'
});
- http://www.example.com/ignored
- http://www.example.com/example.htmlignored
- http://www.example.com?example=trueignored
- http://www.jainaewen.com/files/javascript/jquery/linkManager/#example-sevensame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/fileone.pdfsame
- http://www.jainaewen.com/files/javascript/jquery/linkManager/index.html?query=fileone.pdf#example-sevensame
- #ignored