How to close popup window with a content button?

Hello!
I need an advise very much from you: I use popup window as a modal, when opening the page with concrete ID.
It is working very good. But I need to close popup not with a Close button x, but with my content button withing modal content.
Because there is an agreement and "I Agree" button should be there.
THE QUESTION - how to close popup modal? I tried a huge quantity of codes in onclick, jQuery and so on. Nothing helps... I can't copy function from class mfp-close. All work very good except additional button which must close modal, but does not do that...
Any advise?

Comments

  • In a word - There should be MY Close button ( no problem to create it) inside popup content. And I need to write some code to close this modal, but what code?
  • Done! I do not believe... The morning is better )
    From the scratch - may be someone will use it - the task - to create popup when user enter the concrete page (announcement). Sure - we can use additional plugin, but BE - is powerful theme and to use a plugin for this simple work... not logical.
    1/ Target page: we use ordinary popup code: [popup title="Title" padding="0" button="0"]... [/popup] and create standard popup. Sure beautiful and so on. It was important to disable Close btn for me through Css and to create in modal button - I agree, which will close future modal. Ок - modal tested and ready - then I erase popup Title at all - popup start is hidden at Page now/
    2/ Functions.php : sure in child theme - I make click with JS at my popup when the page is ready (much better then through external JS or BE JS options - I can check - that page or not):
    <pre>
    function is_catalogue(){   
        if ( is_page( array( 146, 2045 ) ) ) {           
            ?>       
                <script type='text/javascript'>          
                    jQuery(document).ready(function($) {
                         $(function(){
                                $('div.ino-popup-win a.popup-link').click();
                            });                      
                    });
                   
                </script>
            <?php
            }   
    }
    add_action('wp_head', 'is_catalogue');
    </pre>
    I can use sessions or cookie here to show popup once.
    Everything is working good. But how to close modal from the button on it?
    3\ That was easy in the morning: I realized that modal - is magnific product and try to add to onclick function:
    <pre>
    $.magnificPopup.close(); return false;
    </pre>
    That is all now - we have popup plugin )
  • Hey,
    did you try to put this JS code by itself into the website?

    <script type='text/javascript'>          
                    jQuery(document).ready(function($) {
                         $(function(){
                                $('div.ino-popup-win a.popup-link').click();
                            });                      
                    });
                   
    </script>

    Also, check your console if there are any JS errors.
    thanks
  • edited August 2019
    hey!
     Yes, I tried. And there is no errors in Console. But Firefox - is ok to close at $.magnificPopup.close(); in
    Chrome generates error when click to close and does not want to close...

    One hour else )) Yes - all working well/ Close procedure ( I write in BE JS):
    jQuery('.close_magnific').on('click',function(){                                                     
        jQuery.magnificPopup.proto.close.call(this);
    });

    and I use class close_magnific in standart Be button.
    Fuh )

    I did some more things - and include cookies to show that windows once... All working fine now...
  • As much as I would like to help you with this, we really do not know what you changed and where. All user modifications or custom code are not supported, espcially PHP or JS.

    thanks
Sign In or Register to comment.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.