Click anywhere closes MagnificPopup ajax box

我与影子孤独终老i 提交于 2019-12-04 11:46:50

Make sure your page that you are "ajax-ing" isn't containing more info or tags than needed. E.g. it should be as clean as this:

<div>
<h3>Heading</h3>
<p>
Text
</p>
</div>

In other words, try avoiding multiple <div>s and don't include <html>, <body> etc. That will unfortunately lead to the behaviour described in the question, of popup closing. I assume it's because it has trouble determining where the content actually is, so it thinks you clicked outside content => closes popup.

closeOnContentClick: false

is already set by default so that won't help, but cleaning up the code to as simple as possible might.

I would also like to mention an alternative: http://nyromodal.nyrodev.com/, which seems to handle things way smoother, and also includes content filtering by id.

add this to your magnific popup options

closeOnContentClick: false

so

$('.ajax-popup-link').magnificPopup({
   type: 'ajax',
   alignTop: false,
   overflowY: 'scroll',
   closeOnContentClick: false
 });

add this to your magnific popup options for click inner white box

 closeOnContentClick: false

Stop closing box when click on black bg

closeOnBgClick:false

Full example

$.magnificPopup.open({
        items: {
            src: '<div class="white-popup"><h1>Modal Test</h1><p>Test Some text.</p><p><a class="popup-modal-dismiss">Dismiss</a></p></div>',
            type:'inline'
        },
       closeOnContentClick: false,
       closeOnBgClick:false
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!