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 = { 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 */ }, // What browsers to display and their order display: ['chrome', 'firefox', 'safari', 'opera', 'gcf', 'msie'], browserShow: true, // Should the browser options be shown? browserInfo: { // Settings for which browsers to display firefox: { text: 'Mozilla Firefox', // Text below the icon url: 'http://www.mozilla.com/firefox/' // URL For icon/text link }, chrome: { text: 'Google Chrome', url: 'http://www.google.com/chrome/' }, safari: { text: 'Safari 5', url: 'http://www.apple.com/safari/download/' }, opera: { text: 'Opera 12', url: 'http://www.opera.com/download/' }, 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', // 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 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']
$('#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; });