Reputation: 231
I m using a magnific popup in my project. To close this popup by jQuery I am using
$('.mfp-close').click();
and it's working but I have need to close by another way.
Please help me if any other way. Thanks in advance.
Upvotes: 22
Views: 59608
Reputation: 1277
This is the only way I could make the popup close:
$('body').on('click', '#some-div', function(e) {
e.preventDefault();
$.magnificPopup.close();
});
Upvotes: 0
Reputation: 1
magnificPopup
iframe:
window.parent.$.magnificPopup.close();
Upvotes: 0
Reputation: 1545
The only one that works for me is :
$jQ('#close_popup').on('click',function(){
$jQ.magnificPopup.proto.close.call(this);
});
Upvotes: 5
Reputation: 419
Take a look here http://dimsemenov.com/plugins/magnific-popup/documentation.html#api
These are some ways you can close this pop up:
var magnificPopup = $.magnificPopup.instance; // save instance in magnificPopup variable
magnificPopup.close(); // Close popup that is currently opened
or
$.magnificPopup.close();
or
$('your-selector').magnificPopup('close');
For me, only the third one worked efficiently.
Upvotes: 16
Reputation: 1625
try this:
var magnificPopup = $.magnificPopup.instance;
// save instance in magnificPopup variable
magnificPopup.close();
// Close popup that is currently opened
Upvotes: 41
Reputation: 40639
If you have open the pop up
then it will return an magnific object
,
Using that object
you can call
close method
.
Try it like,
var mgObj=$('your-selecter').magnificPopup({
// you options
});
// code to close pop up on clicking a button
$(document).on('click','button',function(){
if(mgObj)
{
mgObj.close();
}
});
Upvotes: 0