- Documentation
- Developers
- Javascript API: Methods and Events
Available since version 2.5.6 or higher.
Methods:
- open: It allows to open the popup
- close: It allows to close the popup
Open Popup by ID
1 2 3 4 5 6 | jQuery(document).ready(function ($) { var popup_id = 123; MasterPopups.open(popup_id); //Or using a jQuery selector $('.mpp-popup-' + popup_id).MasterPopups(); }); |
Close Popup by ID
1 2 3 4 | jQuery(document).ready(function ($) { var popup_id = 123; MasterPopups.close(popup_id); }); |
Open Popup and Close
1 2 3 4 5 6 7 | jQuery(document).ready(function ($) { var popup_id = 123; var $popup = MasterPopups.open(popup_id); setTimeout(function () { MasterPopups.close($popup); }, 5000); }); |
Events:
- beforeOpen: It runs before opening the popup
- afterOpen: It runs after opening the popup
- beforeClose: It runs before closing the popup
- afterClose: It runs after closing the popup
- submit: It runs after sending the form
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | jQuery(document).ready(function ($) { MasterPopups.on('beforeOpen', function ($, popup_instance, popup_id, options) { console.log("Before Open Popup"); }); MasterPopups.on('afterOpen', function ($, popup_instance, popup_id, options) { console.log("After Open Popup"); }); MasterPopups.on('beforeClose', function ($, popup_instance, popup_id, options) { console.log("Before Close Popup"); }); MasterPopups.on('afterClose', function ($, popup_instance, popup_id, options) { console.log("After Close Popup"); }); MasterPopups.on('submit', function ($, popup_instance, popup_id, options, success) { console.log("On Form Submit"); }); }); |
Use cases:
Open a Popup by clicking on a button (HTML)
123 is the Popup ID
1 | <a href="#" class="mpp-trigger-popup-123">Open popup</a> |
1 | <a href="mpp-trigger-popup-123">Open popup</a> |
Open a Popup by clicking on a button
1 2 3 4 5 6 | jQuery(document).ready(function ($) { $('.link').on('click', function (e) { var popup_id = 123; MasterPopups.open(popup_id); }); }); |
Contact Form 7: Open a Popup after sending the form
1 2 3 4 5 6 7 | jQuery(document).ready(function ($) { var wpcf7Elm = document.querySelector('.wpcf7'); wpcf7Elm.addEventListener('wpcf7submit', function (event) { var popup_id = 123; MasterPopups.open(popup_id); }, false); }); |
WooCommerce: Open a Popup when updating the Cart
1 2 3 4 5 6 | jQuery(document).ready(function ($) { $('body').on('added_to_cart', function () { var popup_id = 123; MasterPopups.open(popup_id); }); }); |
Was this article helpful?
Like
3
Top Views
Recent topics
Integrations
- Mailchimp
- Mailster (MyMail)
- Sendinblue
- MailPoet
- GetResponse
- MailerLite
- Mautic
- Active Campaign
- Drip
- ConvertKit
- Klaviyo
- FluentCRM
- Constant Contact
- Zoho Campaigns
- Hubspot
- Ontraport
- iContact
- Infusionsoft
- Aweber
- TotalSend
- Campaign Monitor
- Autopilot
- Benchmark Email
- Mad Mimi
- MailWizz
- Freshmail
- E-goi
- SendGrid
- SendPulse
- Agile CRM
- SendPress
- Email Octopus
- Pabbly
- Moosend
- Clever Reach
- Sales Autopilot
- Pipedrive
- SimplyCast
- Customer.io
- TuNewsletter
- Mailgun
- Newsman
- eSputnik
- Automizy
- Zoho CRM