jReject: jQuery Browser Rejection

Current Version: v1.0.0
Last Updated: 12/09/2011 03:42:41

Description: jReject provides a simple, robjust, light-weight way to display rejections based on a the browser, specific browser version, specific platforms, or rendering engine. Provides full customization of the popup. Uses no CSS file (by default), and can easily be used on page load or during a specific page event. Also provides a flexible way to beautifully and cleanly display custom browser alternatives in the popup.

Depends On:
jQuery 1.5+

Download

Example usage documentation below...

Documentation

The object is called "reject", and can be invoked once the document is ready ($.reject() or jQuery.reject()). The first parameter contains all the options and configurations for the plugin.

Default Options

Here are the default options for the first parameter of the reject object. You only need to specify those which you wish to override.

options = {
	reject : { // Rejection flags for specific browsers
		all: false, // Covers Everything (Nothing blocked)
		msie5: true, msie6: true // Covers MSIE 5-6 (Blocked by default)
		/*
			* Possibilities are endless...
			*
			* // MSIE Flags (Global, 5-8)
			* msie, msie5, msie6, msie7, msie8,
			* // Firefox Flags (Global, 1-3)
			* firefox, firefox1, firefox2, firefox3,
			* // Konqueror Flags (Global, 1-3)
			* konqueror, konqueror1, konqueror2, konqueror3,
			* // Chrome Flags (Global, 1-4)
			* chrome, chrome1, chrome2, chrome3, chrome4,
			* // Safari Flags (Global, 1-4)
			* safari, safari2, safari3, safari4,
			* // Opera Flags (Global, 7-10)
			* opera, opera7, opera8, opera9, opera10,
			* // Rendering Engines (Gecko, Webkit, Trident, KHTML, Presto)
			* gecko, webkit, trident, khtml, presto,
			* // Operating Systems (Win, Mac, Linux, Solaris, iPhone)
			* win, mac, linux, solaris, iphone,
			* unknown // Unknown covers everything else
			*/
	},
	display: [], // What browsers to display and their order (default set below)
	browserInfo: { // Settings for which browsers to display
		firefox: {
			text: 'Firefox 4', // Text below the icon
			url: 'http://www.mozilla.com/firefox/' // URL For icon/text link
		},
		safari: {
			text: 'Safari 5',
			url: 'http://www.apple.com/safari/download/'
		},
		opera: {
			text: 'Opera 11',
			url: 'http://www.opera.com/download/'
		},
		chrome: {
			text: 'Chrome 11+',
			url: 'http://www.google.com/chrome/'
		},
		msie: {
			text: 'Internet Explorer 9',
			url: 'http://www.microsoft.com/windows/Internet-explorer/'
		},
		gcf: {
			text: 'Google Chrome Frame',
			url: 'http://code.google.com/chrome/chromeframe/',
			// This browser option will only be displayed for MSIE
			allow: { all: false, msie: true }
		}
	},

	// Header of pop-up window
	header: 'Did you know that your Internet Browser is out of date?',
	// Paragraph 1
	paragraph1: 'Your browser is out of date, and may not be compatible with '+
				'our website. A list of the most popular web browsers can be '+
				'found below.',
	// Paragraph 2
	paragraph2: 'Just click on the icons to get to the download page',
	close: true, // Allow closing of window
	// Message displayed below closing link
	closeMessage: 'By closing this window you acknowledge that your experience '+
					'on this website may be degraded',
	closeLink: 'Close This Window', // Text for closing link
	closeURL: '#', // Close URL
	closeESC: true, // Allow closing of window with esc key

	// If cookies should be used to remmember if the window was closed
	// See cookieSettings for more options
	closeCookie: false,
	// Cookie settings are only used if closeCookie is true
	cookieSettings: {
		// Path for the cookie to be saved on
		// Should be root domain in most cases
		path: '/',
		// Expiration Date (in seconds)
		// 0 (default) means it ends with the current session
		expires: 0
	},

	imagePath: './images/', // Path where images are located
	overlayBgColor: '#000', // Background color for overlay
	overlayOpacity: 0.8, // Background transparency (0-1)

	// Fade in time on open ('slow','medium','fast' or integer in ms)
	fadeInTime: 'fast',
	// Fade out time on close ('slow','medium','fast' or integer in ms)
	fadeOutTime: 'fast'
};
			

Optional Event Methods

options.beforeReject(opts)

Called before rejection is determined.


options.afterReject(opts)

Called after rejection window has been created, for browsers that matched the rejection settings.


options.onFail(opts)

Called if the browser does NOT meet the rejection requirements


options.beforeClose(opts)

Called after close button is clicked, but before popup is actually closed.


options.afterClose(opts)

Called after rejection popup is closed


Example Usage

Default Settings

Run Demo

If nothing happened when you ran this demo, that is because you are not using IE6!
By default (no settings specified) the reject function only rejects IE5 and IE6.

Example Code

		$('#demo1').click(function() {
			$.reject(); // Default Settings
			return false;
		});
			

Customize Browsers To Reject

Run Demo

In this example pretty much every browser should be rejected.

Example Code

		$('#demo2').click(function() {
			$.reject({
				reject: {
					safari: true, // Apple Safari
					chrome: true, // Google Chrome
					firefox: true, // Mozilla Firefox
					msie: true, // Microsoft Internet Explorer
					opera: true, // Opera
					konqueror: true, // Konqueror (Linux)
					unknown: true // Everything else
				}
			}); // Customized Browsers

			return false;
		});
			

Customize Popup Text

Run Demo

In this demo we use customized text in the popup window.
This demo uses the following properties:
header, paragraph1, paragraph2, closeMessage
See Also closeLink

Example Code

		$('#demo3').click(function() {
			$.reject({
				reject: { all: true }, // Reject all renderers for demo
				header: 'Your browser is not supported here', // Header Text
				paragraph1: 'You are currently using an unsupported browser', // Paragraph 1
				paragraph2: 'Please install one of the many optional browsers below to proceed', // Paragraph 2
				closeMessage: 'Close this window at your own demise!' // Message below close window link
			}); // Customized Text

			return false;
		});
			

Customize Browsers To Suggest

Run Demo

Using the display option, you can define which browsers to suggest, and the order in which to suggest them.
GCF is supported, but only displayed for IE users by default.

Default: ['firefox','chrome','msie','safari','opera','gcf']

Example Code

		$('#demo4').click(function() {
			$.reject({
				reject: { all: true }, // Reject all renderers for demo
				display: ['firefox','chrome','opera'] // Displays only firefox, chrome, and opera
			});

			return false;
		});
			

Customize Your Own Browser Suggestion

Run Demo

You can even add a customized browser to the list, and display it in any order you want.

Note: To add your own icon, you need to create a 'browser_{browserName}.gif' file and place it in your imagePath directory with the other images.
Image Dimensions: 100x100
Download browser_konqueror.gif (6.38 KB)

Example Code

		$('#demo5').click(function() {
			$.reject({
				reject: { all: true }, // Reject all renderers for demo
				// Displays only custom "Konqueror" browser, firefox and opera.
				display: ['konqueror','firefox','opera'],
				browserInfo: {
					konqueror: { // Specifies browser name and image name (browser_konqueror.gif)
						text: 'Konqueror 4', // Text Link
						url: 'http://konqueror.kde.org/' // URL To link to
					}
				}
			});

			return false;
		});
			

Display Once Per Session

Run Demo

By using the closeCookie option, you can make the window only appear once per session.
After it pops up the first time, this demo will not popup again until next browser session.

Note: This requires the ability to close the window. If close is false the cookie will never be set.

Example Code

		$('#demo6').click(function() {
			$.reject({
				reject: { all: true }, // Reject all renderers for demo
				closeCookie: true // Set cookie to remmember close for this session
			});

			return false;
		});
			

Disable ability to close window

Run Demo

The close option allows you to hide the closeLink or closeMessage elements from displaying.
This prevents the user from closing the window. If you use this on a onLoad event, the user will never be able to use your site.

Note: Testing this demo will require you to refresh the page to close out the popup window.

Example Code

		$('#demo7').click(function() {
			$.reject({
				reject: { all: true }, // Reject all renderers for demo
				close: false, // Prevent closing of window
				paragraph1: 'You will not be able to close this window', // Warning about closing
				paragraph2: 'To exit, you must <a href="javascript:window.location=window.location.pathname;">refresh the page</a>' // Display refresh link
			});

			return false;
		});