newWindow - open links in a new window in a standards compliant way
Releases
| File / Release | Date Modified | Size | License | Link |
|---|---|---|---|---|
| newWindow 1.1 | 04/05/2010 | 1.06 kB | MIT | Download |
| newWindow 1.1 (packed) | 04/05/2010 | 1.09 kB | MIT | Download |
Resources
Overview
If you're using an XHTML doctype and you are still wanting the functionality of target="_blank", you're in luck with this handy plugin called newWindow.
Generally, forcing the user to open a new window is bad practice, as you should never force the end user to open a page in any predetermined way. However, many clients won't budge on this (they see it as a way to keep the user on the page). Usability guru Jakob Nielsen has written a section explaining why this is a bad idea.
The act of opening a new window is definitely a behaviour, so it should belong in the behaviour layer of a website: JavaScript. As most people today are developing utilising the jQuery framework, I've included this functionality in the form of a jQuery plugin.
There are quite a few of these plugins already out there, but I like mine because it does exactly what I want it to do and it is quite succinct. As well as opening the links in a new window/tab, it will also allow you to modify/add custom text to the title attribute (handy for usability).
Usage
Using this plugin is rather simple. Simply grab a copy of the plugin using the links below (minified one is recommended for production use), include it below where you include jQuery and then run a simple function on DOM ready. Here is an example, complete with the JSON config object.
$(document).ready(function() {
$('a[rel=external]').newWindow({
// This text is added to the title attribute.
titleText: 'Link opens in a new window'
});
});If the titleText is blank, then the title will not be modified at all. Dead simple.
If you have any suggestions, or improvements, please post a comment below. Please note I do realise the packed plugin is currently ever so slightly larger than the raw code. I've left it available anyway, in case someone would like the plugin with a little extra bit of obscurity.
Comments
No comments yet.
Leave a Comment
Note: Your comment may require approval before it is posted to the site.