• Resolved piersrr

    (@piersrr)


    Thank you so much for the plugin. It’s been a real help.

    I am looking to open the modal under certain conditions, in my case triggering it from Javascript in the footer.

    I’ve found bodModal.initModal(); only opens the modal on the page when the modal has already been open (e.g. on page load).

    Is there a way I can call to open a modal through code?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author merbmerb

    (@merbmerb)

    Easiest way to do this is to define the modal so it triggers on a class, you can then trigger the modal by triggering a click on the class via your code.

    Thread Starter piersrr

    (@piersrr)

    Thanks. I’ve added something simple to trigger a click using document.addEventListener(‘DOMContentLoaded’, etc but the modal doesn’t appear?

    The site is here and I have added the click event to the copyright bar at the bottom of the page

    Plugin Author merbmerb

    (@merbmerb)

    Hi

    I could not find your code to trigger the click, but I did my own test. I created a modal using a custom element click on the class ‘launch’. I then used the following code to test

    <p class="triggertest" >Lets do a simple trigger test</p>
    <script>
    document.querySelector('.triggertest').onclick = function() {
    jQuery(".launch").trigger("click");
    };
    
    </script>

    The above code detects a click in the text ‘Lets do a simple trigger test’ and then launches the modal by triggering a click on the class ‘.launch’. Sorry not sure what the JS is but worked without issue using jQuery. Obviously you would just need to use the trigger line where you need it.

    Thread Starter piersrr

    (@piersrr)

    Ah sorry. Thanks for the pointer. I was using document.addEventListener(‘DOMContentLoaded’, function (){//clicker} which wasn’t working, but it worked with: window.onload = function() {//clicker}

    It’s now working! Thanks

    • This reply was modified 10 months, 3 weeks ago by piersrr.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Programmatically open a modal’ is closed to new replies.