jReject: jQuery Browser Rejection
jReject is a simple, light-weight library designed to display a popup based on the browser, specific browser version, specific platforms, or rendering engine. Provides full customization of the popup, and uses a small CSS file. 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.
Requirements
Makes Use Of
jQuery Browser Plugin - Updated version included in default package. (View Original)Download jReject
If you are a developer familiar with using jQuery, continue with the 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 = { // Specifies which browsers/versions will be blocked reject : { all: false, // Covers Everything (Nothing blocked) msie: 6 // Covers MSIE <= 6 (Blocked by default) /* * Many possible combinations. * You can specify browser (msie, chrome, firefox) * You can specify rendering engine (geko, trident) * You can specify OS (Win, Mac, Linux, Solaris, iPhone, iPad) * * You can specify versions of each. * Examples: msie9: true, firefox8: true, * * You can specify the highest number to reject. * Example: msie: 9 (9 and lower are rejected. * * There is also "unknown" that covers what isn't detected * Example: unknown: true */ }, display: [], // What browsers to display and their order (default set below) browserShow: true, // Should the browser options be shown? browserInfo: { // Settings for which browsers to display chrome: { // Text below the icon text: 'Google Chrome', // URL For icon/text link url: 'http://www.google.com/chrome/', // (Optional) Use "allow" to customized when to show this option // Example: to show chrome only for IE users // allow: { all: false, msie: true } }, firefox: { text: 'Mozilla Firefox', url: 'http://www.mozilla.com/firefox/' }, safari: { text: 'Safari', url: 'http://www.apple.com/safari/download/' }, opera: { text: 'Opera', url: 'http://www.opera.com/download/' }, msie: { text: 'Internet Explorer', url: 'http://www.microsoft.com/windows/Internet-explorer/' } }, // Pop-up Window Text header: 'Did you know that your Internet Browser is out of date?', 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.', paragraph2: 'Just click on the icons to get to the download page', // Allow closing of window close: true, // 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', closeURL: '#', // Allows closing of window with esc key closeESC: true, // Use cookies to remmember if window was closed previously? 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 }, // Path where images are located imagePath: './images/', // Background color for overlay overlayBgColor: '#000', // Background transparency (0-1) overlayOpacity: 0.8, // 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', // Google Analytics Link Tracking (Optional) // Set to true to enable // Note: Analytics tracking code must be added separately analytics: false };
Optional Event Methods
options.beforeReject()Called before rejection is determined.
options.afterReject()
Called after rejection window has been created, for browsers that matched the rejection settings.
options.onFail()
Called if the browser does NOT meet the rejection requirements
options.beforeClose()
Called after close button is clicked, but before popup is actually closed.
options.afterClose()
Called after rejection popup is closed
Note: All callbacks can access and edit options by using this
View Demo #8 as an example
Browser Plugin Options
$.browser.className =$.browser.name =
$,browser.version =
$.browser.versionX =
$.os.name =
Example Usage
Demo #1: 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.
$('#demo1').click(function() { $.reject(); // Default Settings return false; });
Demo #2: Customize Browsers To Reject
Run DemoIn this example pretty much every browser should be rejected.
$('#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; });
Demo #3: 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
$('#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', closeMessage: 'Close this window at your own demise!' // Message below close window link }); // Customized Text return false; });
Demo #4: Customize Browsers To Suggest
Run DemoUsing the display option, you can define which browsers to suggest, and the order in which to suggest them.
Default: ['firefox','chrome','msie','safari','opera']
$('#demo4').click(function() { $.reject({ reject: { all: true }, // Reject all renderers for demo display: ['firefox','chrome','opera'] // Displays only firefox, chrome, and opera }); return false; });
Demo #5: Customize Your Own Browser Suggestion
Run DemoYou 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
$('#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; });
Demo #6: 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.
$('#demo6').click(function() { $.reject({ reject: { all: true }, // Reject all renderers for demo closeCookie: true // Set cookie to remmember close for this session }); return false; });
Demo #7: 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.
$('#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>' }); return false; });
Demo #8: Customize by Browser
Run Demo
This example uses the beforeReject callback to change options by browser.
In chrome, only FireFox and Opera options will be displayed. iPhone/iPad displays no browser options
$('#demo8').click(function() { $.reject({ reject: { all: true }, // Reject all renderers for demo beforeReject: function() { if ($.browser.name === 'chrome') { this.display = ['firefox','opera']; } if ($.os.name === 'iphone' || $.os.name === 'ipad') { this.browserShow = false; this.paragraph2 = ''; } } }); return false; });