If you need a quick and easy way to toggle and Oxygen Builder modal on what a URL contains, use the code and steps in this article.
First, here's what this code does. Say your URL contains the parameter example.com/?toggle-modal=yes. We're going to set up a simple code block that will toggle a modal to pop up if the url contains that text.
First, add a code box and button to your page. Note the buttons ID, then go to Advanced -> Layout, and hide it.
Now, go to the modal, select the trigger type "show when user clicks element", and paste in the button id.
Make a code block (anywhere on the page works), and paste this code into the JS section.
(function($) {
$(document).ready(function () {
if(window.location.href.indexOf("urlparam=this") > -1) {
document.querySelector('#modal_toggle').click();
}
});
})( jQuery );
Code language: JavaScript (javascript)
Essentially, it sees that your url contains the parameter needed to toggle the modal, and clicks the (hidden) button, triggering the modal to pop up.
This is great if you're redirecting visitors to a page, sending them from an email, or just want to toggle an Oxygen Builder modal from a URL Paramater.
Oooh... my mind is spinning with the possibilities
Hi James,
For some reason it is not working for me. Does it work with the latest Oxygen Builder?