### Disable Ouibounce and Set Cookie Source: https://context7.com/carlsednaoui/ouibounce/llms.txt Disables Ouibounce and sets a cookie to prevent future modal triggers. This method can be called programmatically, for example, when a user manually closes the modal. It accepts an optional configuration object to customize the cookie's expiration, domain, and sitewide applicability. ```javascript var modal = ouibounce(document.getElementById('ouibounce-modal')); // Simple disable - uses default cookie settings modal.disable(); // Disable with custom cookie expiration (50 days) sitewide modal.disable({ cookieExpire: 50, sitewide: true }); // Disable across all subdomains modal.disable({ cookieExpire: 30, cookieDomain: '.example.com', sitewide: true }); // Use case: User closes modal manually document.querySelector('.close-button').addEventListener('click', function() { document.getElementById('ouibounce-modal').style.display = 'none'; modal.disable({ cookieExpire: 7 }); // Don't show again for 7 days }); ``` -------------------------------- ### Combine Ouibounce Options Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Demonstrates how to chain multiple Ouibounce configuration options together in a single call to customize behavior comprehensively. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true, sitewide: true, cookieDomain: '.example.com', timer: 0, callback: function() { console.log('ouibounce fired!'); } }); ``` -------------------------------- ### Ouibounce Initialization and Options Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Initialize Ouibounce with various configuration options to customize its behavior, such as setting timers, delays, callbacks, and cookie settings. ```APIDOC ## Ouibounce Initialization and Options ### Description Initialize Ouibounce with various configuration options to customize its behavior, such as setting timers, delays, callbacks, and cookie settings. ### Method `ouibounce(element, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body **element** (HTMLElement | false) - The DOM element to attach Ouibounce to, or `false` to use it with other libraries. **options** (Object) - Configuration options for Ouibounce. - **timer** (Number) - Minimum time in milliseconds before Ouibounce fires. Defaults to 1000 (1 second). - **delay** (Number) - Delay in milliseconds before showing the modal. If the mouse re-enters the body before this delay, the modal won't appear. - **callback** (Function) - A function to execute once Ouibounce has been triggered. - **cookieExpire** (Number) - Number of days before the Ouibounce cookie expires. Defaults to session end. - **cookieDomain** (String) - The domain under which the cookie should work. Use '.example.com' for subdomains. - **cookieName** (String) - Custom name for the Ouibounce cookie. - **sitewide** (Boolean) - If true, drops sitewide cookies. Defaults to false. - **aggressive** (Boolean) - Enables aggressive mode (use with caution). ### Request Example ```javascript // Set a minimum time before Ouibounce fires (0ms) ouibounce(document.getElementById('ouibounce-modal'), { timer: 0 }); // Delay showing the modal by 100ms ouibounce(document.getElementById('ouibounce-modal'), { delay: 100 }); // Add a callback function ouibounce(document.getElementById('ouibounce-modal'), { callback: function() { console.log('Ouibounce fired!'); } }); // Set cookie expiration to 10 days ouibounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10 }); // Set cookie domain for subdomains ouibounce(document.getElementById('ouibounce-modal'), { cookieDomain: '.example.com' }); // Specify a custom cookie name ouibounce(document.getElementById('ouibounce-modal'), { cookieName: 'customCookieName' }); // Enable sitewide cookies ouibounce(document.getElementById('ouibounce-modal'), { sitewide: true }); // Combine multiple options ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true, sitewide: true, cookieDomain: '.example.com', timer: 0, callback: function() { console.log('ouibounce fired!'); } }); // Using Ouibounce with other libraries var _ouibounce = ouibounce(false, { callback: function() { console.log('ouibounce fired!'); } }); ``` ### Response #### Success Response (200) Returns an object with methods to control Ouibounce. #### Response Example ```javascript { fire: function() { /* ... */ }, disable: function(options) { /* ... */ } } ``` ``` -------------------------------- ### Use Ouibounce with Other Libraries Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Illustrates how to initialize Ouibounce with 'false' to integrate it with other libraries, as discussed in issue #30. ```javascript var _ouibounce = ouibounce(false, { callback: function() { console.log('ouibounce fired!'); } }); ``` -------------------------------- ### Initialize Ouibounce with Callback and Counter Source: https://github.com/carlsednaoui/ouibounce/blob/master/test/fixtures/basic.html This snippet demonstrates how to initialize ouibounce with a specific element and a callback function. The callback increments a counter, useful for testing aggressive mode or tracking exit intent triggers. No external dependencies are required beyond the ouibounce library itself. ```javascript // initialize a counter, to test aggressive mode window.ouibounceCounter = 0; ouibounce(document.getElementById('ouibounce-modal'), { callback: function() { window.ouibounceCounter++; } }); ``` -------------------------------- ### Initialize Ouibounce with Vanilla JavaScript Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md This snippet demonstrates the basic initialization of Ouibounce using vanilla JavaScript. It selects a modal element by its ID and passes it to the ouibounce function. No external libraries are required for this basic usage. ```javascript ouibounce(document.getElementById('ouibounce-modal')); ``` -------------------------------- ### Initialize ouibounce with Callback and Aggressive Mode (JavaScript) Source: https://github.com/carlsednaoui/ouibounce/blob/master/test/fixtures/manual.html This snippet demonstrates how to initialize the ouibounce library. It sets up a modal element to trigger an exit-intent event and uses the 'aggressive' option to fire more readily. A callback function is provided to set a global flag when the event fires. ```javascript window.ouibounceFired = false; window.modal = ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true, callback: function() { window.ouibounceFired = true; } }); ``` -------------------------------- ### Initialize ouibounce with Callback and Aggressive Mode Source: https://github.com/carlsednaoui/ouibounce/blob/master/test/fixtures/aggressive.html This snippet shows how to initialize the ouibounce library to display a modal when a user is about to leave the page. It includes a counter to track modal displays and sets the library to aggressive mode. The callback function increments the counter each time the modal is triggered. ```javascript window.ouibounceCounter = 0; if (window.document.cookie === 'viewedOuibounceModal=true') { window.ouibounceCounter = 1; } ouibounce(document.getElementById('ouibounce-modal'), { callback: function() { window.ouibounceCounter++; }, aggressive: true }); ``` -------------------------------- ### Initialize Ouibounce Modal with Configuration Source: https://context7.com/carlsednaoui/ouibounce/llms.txt Initializes Ouibounce on a specified DOM element, enabling exit-intent detection and displaying a modal. This function accepts a configuration object to customize various aspects like sensitivity, timers, cookies, and callbacks. It returns an instance object with methods to control the modal's behavior. ```javascript var modal = document.getElementById('ouibounce-modal'); ouibounce(modal); // With jQuery ouibounce($('#ouibounce-modal')[0]); // Full configuration example var instance = ouibounce(document.getElementById('ouibounce-modal'), { sensitivity: 40, // How close to viewport top before firing (default: 20) timer: 0, // Milliseconds before Ouibounce activates (default: 1000) delay: 100, // Grace period in ms before showing modal (default: 0) aggressive: true, // Fire on every page load, ignore cookie (default: false) cookieExpire: 30, // Cookie expiration in days (default: session) cookieDomain: '.example.com', // Domain for cookie (default: current domain) cookieName: 'exitModal', // Custom cookie name (default: 'viewedOuibounceModal') sitewide: true, // Cookie applies to entire site (default: false) callback: function() { console.log('Exit intent detected!'); // Track analytics, trigger other events, etc. } }); /* HTML modal structure
*/ ``` -------------------------------- ### Initialize OuiBounce with Callback and Aggressive Mode (JavaScript) Source: https://github.com/carlsednaoui/ouibounce/blob/master/test/index.html Initializes the OuiBounce library to display a modal when a user attempts to leave the page. It uses aggressive mode for immediate triggering and a callback function to log a message when OuiBounce fires. Dependencies include the OuiBounce library itself. ```javascript var _ouibounce = ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true, timer: 0, callback: function() { console.log('ouibounce fired!'); } }); ``` -------------------------------- ### Ouibounce Integration with Third-Party Modals (JavaScript) Source: https://context7.com/carlsednaoui/ouibounce/llms.txt Shows how to integrate Ouibounce with Vex, SweetAlert, and Bootstrap modals. Ouibounce is initialized with `false`, and its `callback` option is used to trigger the respective modal libraries when exit intent is detected. This allows for flexible implementation of exit-intent popups without relying on Ouibounce's default modal. ```javascript var _ouibounce = ouibounce(false, { callback: function() { vex.dialog.alert({ message: 'Before you go, sign up for our newsletter!', callback: function() { console.log('User acknowledged the modal'); } }); } }); var exitIntent = ouibounce(false, { sensitivity: 30, timer: 2000, callback: function() { Swal.fire({ title: 'Wait!', text: 'Get 15% off your purchase', icon: 'info', showCancelButton: true, confirmButtonText: 'Yes, get discount!' }).then(function(result) { if (result.isConfirmed) { window.location.href = '/discount-signup'; } }); } }); var bootstrapExit = ouibounce(false, { callback: function() { $('#bootstrapModal').modal('show'); } }); ``` -------------------------------- ### Initialize and Control OuiBounce Modal (JavaScript) Source: https://github.com/carlsednaoui/ouibounce/blob/master/test/sitewide-cookies.html This snippet shows how to initialize OuiBounce with custom options like cookie expiration and a callback function. It also demonstrates how to save the OuiBounce instance to a variable to later disable it, and how to handle click events to hide the modal and disable OuiBounce. ```javascript var _ouiBounce = ouibounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10, timer: 0, callback: function() { console.log('ouiBounce fired!'); } }); $('.underlay').on('click', function() { $('#ouibounce-modal').hide(); _ouiBounce.disable({ cookieExpire: 5, sitewide: true }); }); $('#ouibounce-modal .modal-footer').on('click', function() { $('#ouibounce-modal').hide(); _ouiBounce.disable({ cookieExpire: 5, sitewide: true }); }); $('#ouibounce-modal .modal').on('click', function(e) { e.stopPropagation(); }); ``` -------------------------------- ### Configure Ouibounce Callback Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Add a callback function that executes once Ouibounce has been triggered. This allows for custom actions upon popup activation. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { callback: function() { console.log('Ouibounce fired!'); } }); ``` -------------------------------- ### Using Ouibounce Public API to Fire Modal Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md This snippet illustrates how to use the Ouibounce public API to manually trigger the modal. After initializing Ouibounce and saving the returned object, you can call the `fire()` method on this object to display the modal on demand. This is useful for custom event handling. ```javascript var modal = ouibounce(document.getElementById('ouibounce-modal')); modal.fire() ``` -------------------------------- ### Enable Ouibounce Aggressive Mode Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md This snippet shows how to enable the `aggressive` mode in Ouibounce. When `aggressive` is set to `true`, the modal can fire every time the page is reloaded for the same user, overriding the default behavior of firing only once per visitor. This is useful for paid landing pages. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true }); ``` -------------------------------- ### Ouibounce API: Fire and Disable Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Shows how to use the Ouibounce API by saving the returned object to fire the event on demand or disable it with optional parameters for cookie settings. ```javascript 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. ``` -------------------------------- ### Configure Ouibounce Timer Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Set a minimum time in milliseconds before Ouibounce fires to prevent false positives. A value of 0 means it can fire immediately. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { timer: 0 }); ``` -------------------------------- ### Configure Ouibounce Delay Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Set a delay in milliseconds before the modal appears. If the user's mouse re-enters the body before the delay, the modal will not show, providing a grace period. ```javascript // Wait 100 ms ouibounce(document.getElementById('ouibounce-modal'), { delay: 100 }); ``` -------------------------------- ### Configure Ouibounce Cookie Domain Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Specify the cookie domain to ensure the cookie works across subdomains. Prefix with a dot (e.g., '.example.com') for subdomain support. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { cookieDomain: '.example.com' }); ``` -------------------------------- ### Initialize Ouibounce with jQuery Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md This snippet shows how to initialize Ouibounce using jQuery. It selects the modal element using a jQuery selector and then accesses the first element of the jQuery object to pass to the ouibounce function. This requires the jQuery library to be included in the project. ```javascript ouibounce($('#ouibounce-modal')[0]); ``` -------------------------------- ### Ouibounce API Control Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Access the Ouibounce public API by saving the returned object from the `ouibounce` function to programmatically fire or disable the modal. ```APIDOC ## Ouibounce API Control ### Description Access the Ouibounce public API by saving the returned object from the `ouibounce` function to programmatically fire or disable the modal. ### Method `ouibounce(element, options)` returns an API object. ### Endpoint N/A (JavaScript API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### API Object Methods - **fire()**: Programmatically triggers the Ouibounce event. - **disable(options)**: Disables Ouibounce. Accepts optional `disable` options: - **cookieExpire** (Number): Number of days before the cookie expires. - **cookieDomain** (String): The domain for the cookie. - **cookieName** (String): Custom name for the cookie. - **sitewide** (Boolean): If true, drops sitewide cookies. ### Request Example ```javascript // Initialize Ouibounce and get the API object var modal = ouibounce(document.getElementById('ouibounce-modal')); // Fire the Ouibounce event on demand modal.fire(); // Disable Ouibounce modal.disable(); // Disable Ouibounce with specific options modal.disable({ cookieExpire: 50, sitewide: true }); ``` ### Response #### Success Response (200) N/A (JavaScript API) #### Response Example N/A ``` -------------------------------- ### Handle Modal Clicks and Hiding (jQuery) Source: https://github.com/carlsednaoui/ouibounce/blob/master/test/index.html Provides JavaScript code using jQuery to manage the visibility of the OuiBounce modal. It hides the modal when the user clicks anywhere on the body, specifically within the modal footer, or when clicks occur within the modal content itself to prevent accidental closing. ```javascript $('body').on('click', function() { $('#ouibounce-modal').hide(); }); $('#ouibounce-modal .modal-footer').on('click', function() { $('#ouibounce-modal').hide(); }); $('#ouibounce-modal .modal').on('click', function(e) { e.stopPropagation(); }); ``` -------------------------------- ### Configure Ouibounce Sitewide Cookie Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Enable sitewide cookies by setting the 'sitewide' option to true. This affects cookie behavior across the entire site. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { sitewide: true }); ``` -------------------------------- ### Programmatically Trigger Ouibounce Modal Source: https://context7.com/carlsednaoui/ouibounce/llms.txt Triggers the Ouibounce modal display programmatically, bypassing the default exit-intent detection. This is useful for testing the modal or for triggering it based on custom user interactions or page events, such as scrolling to a certain depth or after a specific time on page. ```javascript var modal = ouibounce(document.getElementById('ouibounce-modal')); // Trigger modal after 30 seconds on page setTimeout(function() { modal.fire(); }, 30000); // Or trigger based on scroll depth window.addEventListener('scroll', function() { var scrollPercent = (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100; if (scrollPercent > 75) { modal.fire(); } }); ``` -------------------------------- ### Configure Ouibounce Sensitivity Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md This snippet demonstrates how to configure the sensitivity option for Ouibounce. The `sensitivity` option controls how close the mouse cursor needs to be to the top of the viewport to trigger the modal. A higher value means the modal will fire more quickly. The default value is 20. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { sensitivity: 40 }); ``` -------------------------------- ### Configure Ouibounce Cookie Name Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Customize the name of the cookie used to track if the modal has been shown to a user. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { cookieName: 'customCookieName' }); ``` -------------------------------- ### Check if Ouibounce is Disabled Source: https://context7.com/carlsednaoui/ouibounce/llms.txt Returns a boolean value indicating whether Ouibounce is currently disabled. This check is useful for implementing conditional logic, such as preventing the modal from firing if a disabling cookie already exists and the `aggressive` option is not enabled. It helps in managing user experience by not repeatedly showing the modal. ```javascript var modal = ouibounce(document.getElementById('ouibounce-modal'), { aggressive: false }); // Check if modal can still fire if (!modal.isDisabled()) { console.log('Exit intent modal is active'); } else { console.log('User has already seen the modal'); } // Conditional tracking function trackPageView() { var data = { page: window.location.pathname, exitModalAvailable: !modal.isDisabled() }; // Send to analytics console.log('Page view:', data); } ``` -------------------------------- ### Configure Ouibounce Cookie Expiration Source: https://github.com/carlsednaoui/ouibounce/blob/master/README.md Set the cookie expiration in days to control how often the modal appears for a user. By default, it expires at the end of the session. ```javascript ouibounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10 }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.