Opening new browser window with jQuery plugin
newWindow is a super-simple jQuery plugin for opening new browser windows when an anchor is clicked.
Code:
(function ($) { $.extend($.fn, { newWindow: function (options) { var defaults = {open: function () {}}; options = $.extend(defaults, options || {}); return this.each(function () { $(this).click(function (e) { e.preventDefault(); var newWindow = open(this.href); options.open.call(newWindow, e); }); }); } }); })(jQuery);
Usage
Open all links with a rel
attribute of external
in a new window:
$('a[rel~=external]').newWindow();
Add a callback when a new window is opened:
$('#myLink').newWindow({ open: function (newWindow, e) { console.log('Window opened', newWindow, e); } });
Licensing
Licensed under the MIT: http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2011 Stateless Systems (http://statelesssystems.com)
You might also like
Tags
accordion accordion menu animation navigation animation navigation menu carousel checkbox inputs css3 css3 menu css3 navigation date picker dialog drag drop drop down menu drop down navigation menu elastic navigation form form validation gallery glide navigation horizontal navigation menu hover effect image gallery image hover image lightbox image scroller image slideshow multi-level navigation menus rating select dependent select list slide image slider menu stylish form table tabs text effect text scroller tooltips tree menu vertical navigation menu