Top Related Projects
jQuery BlockUI Plugin
A collection of loading indicators animated with CSS
A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in CSS, Sass, and LESS.
A modern dialog library which is highly configurable and easy to style. #hubspot-open-source
⛔️ DEPRECATED - Dependency-free notification library that makes it easy to create alert - success - error - warning - information - confirmation messages as an alternative the standard alert dialog.
Quick Overview
The ouibounce
project is a JavaScript library that displays a modal or other content when a user attempts to leave a website. It is designed to capture the user's attention and encourage them to stay on the site, potentially leading to increased engagement or conversions.
Pros
- Customizable: The library provides a range of options for customizing the appearance and behavior of the modal, allowing developers to integrate it seamlessly into their website's design.
- Cross-browser Compatibility: The library is designed to work across a wide range of modern web browsers, ensuring a consistent user experience.
- Lightweight: The library is relatively small in size, with a minified and gzipped version weighing in at around 2KB, making it suitable for use on performance-sensitive websites.
- Flexible: The library can be used to display a variety of content, not just a simple modal, allowing for more creative and engaging user experiences.
Cons
- Potential for Annoyance: While the library is designed to capture the user's attention, it could be perceived as intrusive or annoying, especially if not implemented thoughtfully.
- Potential for Accessibility Issues: The use of modals can create accessibility challenges, and developers should ensure that the library is integrated in a way that maintains good accessibility practices.
- Dependency on jQuery: The library currently requires the use of jQuery, which may not be desirable for all projects or developers who prefer to use vanilla JavaScript.
- Limited Customization Options: While the library is customizable, the range of options may be limited compared to building a custom solution from scratch.
Code Examples
Here are a few examples of how to use the ouibounce
library:
- Basic Usage:
var modal = ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0,
callback: function() { console.log('ouibounce fired!'); }
});
$('#ouibounce-modal').on('click', function() {
modal.disable();
});
This code creates a basic modal that is displayed when the user attempts to leave the page. The aggressive
option is set to true
, which means the modal will be displayed regardless of the user's mouse movement. The timer
option is set to 0
, which means the modal will be displayed immediately. The callback
function is called when the modal is displayed.
- Customizing the Modal Content:
ouibounce(document.getElementById('ouibounce-modal'), {
title: 'Wait, don\'t go!',
message: 'Sign up to our newsletter for updates and special offers.',
delay: 5000,
cookieExpire: 7,
sitewide: true
});
This code customizes the content of the modal, including the title, message, and delay before the modal is displayed. The cookieExpire
option sets the duration of the cookie that is used to track whether the user has already seen the modal, and the sitewide
option ensures the modal is displayed on all pages of the website.
- Disabling the Modal:
var modal = ouibounce(document.getElementById('ouibounce-modal'));
// Disable the modal after 10 seconds
setTimeout(function() {
modal.disable();
}, 10000);
This code creates a modal and then disables it after 10 seconds using the disable()
method.
Getting Started
To use the ouibounce
library, follow these steps:
- Include the library in your HTML file:
<script src="https://cdn.jsdelivr.net/npm/ouibounce@0.0.12/dist/ouibounce.min.js"></script>
- Create a container element for the modal:
<div id="ouibounce-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
Competitor Comparisons
jQuery BlockUI Plugin
Pros of BlockUI
- More versatile, can block entire page, elements, or overlay custom content
- Supports jQuery integration for easier implementation
- Offers more customization options for appearance and behavior
Cons of BlockUI
- Larger file size and potentially heavier performance impact
- Requires jQuery as a dependency
- May be overly complex for simple exit-intent popups
Code Comparison
BlockUI:
$.blockUI({
message: '<h1>Processing...</h1>',
css: { border: 'none', padding: '15px', backgroundColor: '#000', color: '#fff' }
});
OuiBounce:
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0,
callback: function() { console.log('OuiBounce fired!'); }
});
Key Differences
- BlockUI is a more general-purpose blocking/overlay solution, while OuiBounce focuses specifically on exit-intent popups
- OuiBounce is lightweight and standalone, whereas BlockUI requires jQuery
- BlockUI offers more extensive customization options, but OuiBounce is simpler to implement for its specific use case
Use Cases
- Choose BlockUI for versatile content blocking and custom overlays in jQuery-based projects
- Opt for OuiBounce when you need a lightweight, specific solution for exit-intent popups without additional dependencies
A collection of loading indicators animated with CSS
Pros of SpinKit
- Offers a wide variety of CSS-only loading spinners
- Lightweight and easy to implement
- Customizable with CSS variables
Cons of SpinKit
- Limited to loading animations only
- Requires additional JavaScript for dynamic behavior
- May not be suitable for complex user interactions
Code Comparison
SpinKit (CSS):
.spinner {
width: 40px;
height: 40px;
background-color: #333;
animation: sk-rotateplane 1.2s infinite ease-in-out;
}
Ouibounce (JavaScript):
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0,
callback: function() { console.log('ouibounce fired!'); }
});
SpinKit focuses on providing CSS-based loading animations, while Ouibounce is a JavaScript library for exit-intent popups. SpinKit's code snippet shows a simple CSS animation, whereas Ouibounce's code demonstrates how to initialize an exit-intent popup with various options.
SpinKit is ideal for adding loading indicators to web applications, offering a range of pre-built, customizable spinners. On the other hand, Ouibounce serves a different purpose by helping to capture users' attention before they leave a website.
While both libraries enhance user experience, they target different aspects of web development. SpinKit improves perceived loading times, and Ouibounce aims to increase user engagement and conversion rates.
A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in CSS, Sass, and LESS.
Pros of Hover
- Offers a wide variety of CSS hover effects, providing more design options
- Easier to implement for multiple elements across a website
- Regularly maintained with frequent updates
Cons of Hover
- Limited to hover effects only, not addressing exit-intent functionality
- May require more manual customization for specific use cases
- Potentially larger file size due to numerous effect options
Code Comparison
Hover:
.hover-effect {
display: inline-block;
vertical-align: middle;
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
backface-visibility: hidden;
}
Ouibounce:
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0,
callback: function() { console.log('ouibounce fired!'); }
});
The code snippets demonstrate the different focus of each library. Hover provides CSS classes for various hover effects, while Ouibounce uses JavaScript to detect exit-intent and trigger actions. Hover is more suited for enhancing visual interactions, whereas Ouibounce is specifically designed for exit-intent popups and related functionality.
A modern dialog library which is highly configurable and easy to style. #hubspot-open-source
Pros of vex
- More versatile and feature-rich, offering various dialog types and customization options
- Better documentation and examples, making it easier for developers to implement
- Actively maintained with regular updates and bug fixes
Cons of vex
- Larger file size and potentially more complex to implement for simple use cases
- May have a steeper learning curve for developers new to the library
- Requires additional CSS for styling, which can increase implementation time
Code Comparison
vex:
vex.dialog.alert({
message: 'Thanks for visiting our site!',
className: 'vex-theme-default'
});
ouibounce:
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0
});
Summary
vex is a more comprehensive solution for creating dialogs and modals, offering greater flexibility and customization options. It's well-maintained and documented, making it suitable for complex projects. However, this comes at the cost of a larger file size and potentially more complex implementation.
ouibounce, on the other hand, is specifically designed for exit-intent popups, making it simpler to implement for this particular use case. It has a smaller footprint but offers fewer features and customization options compared to vex.
Choose vex for versatile dialog needs in larger projects, and ouibounce for quick and simple exit-intent popup implementation in smaller projects or specific use cases.
⛔️ DEPRECATED - Dependency-free notification library that makes it easy to create alert - success - error - warning - information - confirmation messages as an alternative the standard alert dialog.
Pros of noty
- More versatile notification system with multiple types and positions
- Actively maintained with regular updates and bug fixes
- Extensive documentation and examples for easy implementation
Cons of noty
- Larger file size and potentially more complex to set up
- May be overkill for simple exit-intent popups
Code Comparison
noty:
new Noty({
text: 'Hello, world!',
type: 'success',
layout: 'topRight',
timeout: 3000
}).show();
ouibounce:
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0,
callback: function() { console.log('ouibounce fired!'); }
});
Summary
noty is a comprehensive notification library offering various types and positions for notifications, while ouibounce focuses specifically on exit-intent popups. noty provides more flexibility and options but may be excessive for simple exit-intent functionality. ouibounce is more lightweight and straightforward for its specific use case but lacks the versatility of noty. The choice between the two depends on the project's requirements and complexity.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Ouibounce
Originally created by Carl Sednaoui from MailCharts. Maintained and improved by generous contributors.
Ouibounce: A small library enabling you to display a modal before a user leaves your website.
Quick note: Let me know if you end up using Ouibounce. I'd love to hear about your project / see Ouibounce in the wild :)
The philosophy behind this project
This library helps you increase landing page conversion rates. From my experience, you can expect a lift of 7% to 15% depending on your audience, traffic type (paid or unpaid) and copy.
Talking about copy... please use Ouibounce to provide value to your visitors. With tools like these it's very easy to create something spammy-looking.
Not sure what I mean by provide value? Here are a few ideas to get your creative juices flowing:
- Free ebook
- Upcoming webinar invite
- Exclusive access to XYZ
- A full educational course
- Valuable content
Demo / Examples
Modal inspiration
I've designed a few modals just for you. Feel free to use these as inspiration.
Installation
You have a few options to choose from:
- Download the minified or unminified script and include it on your page
- Get Ouibounce from cdnjs.com
- Use Bower:
curl http://bower.herokuapp.com/packages/ouibounce
- Use NPM:
npm install ouibounce
Note: Ouibounce is wrapped by a umd wrapper, so if you are using requirejs/amd or commonjs/browserify, it will still work fine.
Usage
- Create a hidden modal
- Select the modal with vanilla JavaScript (or jQuery) and call
ouibounce
- Optional: Save the function's return value to use the public API, allowing you to
fire
ordisable
Ouibounce on demand
Example:
ouibounce(document.getElementById('ouibounce-modal'));
Example with jQuery:
ouibounce($('#ouibounce-modal')[0]);
Example using the public api:
var modal = ouibounce(document.getElementById('ouibounce-modal'));
modal.fire()
Options
Ouibounce offers a few options, such as:
- Sensitivity
- Aggressive mode
- Timer
- Delay
- Callback
- Cookie expiration
- Cookie domain
- Cookie name
- Sitewide cookie
- Chaining options
Sensitivity
Ouibounce fires when the mouse cursor moves close to (or passes) the top of the viewport. You can define how far the mouse has to be before Ouibounce fires. The higher value, the more sensitive, and the more quickly the event will fire. Defaults to 20.
Example:
ouibounce(document.getElementById('ouibounce-modal'), { sensitivity: 40 });
Aggressive mode
By default, Ouibounce will only fire once for each visitor. When Ouibounce fires, a cookie is created to ensure a non obtrusive experience.
There are cases, however, when you may want to be more aggressive (as in, you want the modal to be elegible to fire anytime the page is loaded/ reloaded). An example use-case might be on your paid landing pages. If you enable aggressive
, the modal will fire any time the page is reloaded, for the same user.
Example:
ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true });
Set a min time before Ouibounce fires
By default, Ouibounce won't fire in the first second to prevent false positives, as it's unlikely the user will be able to exit the page within less than a second. If you want to change the amount of time that firing is surpressed for, you can pass in a number of milliseconds to timer
.
Example:
ouibounce(document.getElementById('ouibounce-modal'), { timer: 0 });
Delay
By default, Ouibounce will show the modal immediately. You could instead configure it to wait x
milliseconds before showing the modal. If the user's mouse re-enters the body before delay
ms have passed, the modal will not appear. This can be used to provide a "grace period" for visitors instead of immediately presenting the modal window.
Example:
// Wait 100 ms
ouibounce(document.getElementById('ouibounce-modal'), { delay: 100 });
Callback
You can add a callback, which is a function that will run once Ouibounce has been triggered, by using the callback
option.
Example:
ouibounce(document.getElementById('ouibounce-modal'), { callback: function() { console.log('Ouibounce fired!'); } });
Cookie expiration
Ouibounce sets a cookie by default to prevent the modal from appearing more than once per user. You can add a cookie expiration (in days) using cookieExpire
to adjust the time period before the modal will appear again for a user. By default, the cookie will expire at the end of the session, which for most browsers is when the browser is closed entirely.
Example:
ouibounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10 });
Cookie domain
Ouibounce sets a cookie by default to prevent the modal from appearing
more than once per user. You can add a cookie domain using
cookieDomain
to specify the domain under which the cookie should work.
By default, no extra domain information will be added. If you need a
cookie to work also in your subdomain (like blog.example.com and
example.com), then set a cookieDomain such as .example.com (notice the
dot in front).
Example:
ouibounce(document.getElementById('ouibounce-modal'), { cookieDomain:
'.example.com' });
Cookie name
You can specify cookie name passing cookieName: 'customCookieName'
.
Example:
ouibounce(document.getElementById('ouibounce-modal'), { cookieName: 'customCookieName' });
Sitewide cookie
You can drop sitewide cookies by using passing sitewide: true
.
Example:
ouibounce(document.getElementById('ouibounce-modal'), { sitewide: true });
Chaining options
The options are just javascript objects, you can therefore combine multiple options.
Example:
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
sitewide: true,
cookieDomain: '.example.com',
timer: 0,
callback: function() { console.log('ouibounce fired!'); }
});
Ouibounce API
If you save the object returned by the ouibounce
function, you get access to a small public API. Use this API to fire
or disable
Ouibounce on demand.
Example:
var modal = ouibounce(document.getElementById('ouibounce-modal'));
modal.fire(); // fire the ouibounce event
modal.disable() // disable ouibounce, it will not fire on page exit
modal.disable({ cookieExpire: 50, sitewide: true }) // disable ouibounce sitewide for 50 days.
Disable options
The disable
function accepts a few options:
Using Ouibounce with other libraries
If you want to use this library with other plugins â such as Vex â you can call ouibounce with false
. See #30 for discussion.
var _ouibounce = ouibounce(false, {
callback: function() { console.log('ouibounce fired!'); }
});
Twitter Bootstrap
If you're trying to use Ouibounce with Twitter Bootstrap and are simply copying the example code I've included in the demo, you might run into some problems. See #66 to fix this.
Legacy JS engines
If you'd like Ouibounce to work in legacy JS engines (IE8 and below, for example), you'll need to add a shim such as es5-shim.
WordPress
Tomaž wrote a great tutorial on how to build your own WordPress opt-in form.
Kevin Weber wrote wBounce, a WordPress plugin. I personally have not tested it, but have heard it works really well. Check it out.
Miscellaneous
- This library provides no guarantees.
- If you are intersted in contributing, make sure to check out contributing.md.
- Licensed under MIT.
- Special thanks to Zertosh, Jenius and all other contributors.
Top Related Projects
jQuery BlockUI Plugin
A collection of loading indicators animated with CSS
A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in CSS, Sass, and LESS.
A modern dialog library which is highly configurable and easy to style. #hubspot-open-source
⛔️ DEPRECATED - Dependency-free notification library that makes it easy to create alert - success - error - warning - information - confirmation messages as an alternative the standard alert dialog.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot