4

What is the best way to test if a Magnific Popup is currently "open"?

Will a check for the existence of some div be future proof?

For example, if I use:

if ($(".mfp-ready").length > 0)
  ...

I looked for the equivilent of an isopen property in the api documentation but found nothing like that

EDIT

Following Dmitry's answer, I examined the instance object and found the following properties that may prove useful to others:

isAndroid
isIE7
isIE8
isIOS
isLowIE
Graham
  • 7,807
  • 20
  • 69
  • 114

3 Answers3

11

$.magnificPopup.instance.isOpen

Dmitry Semenov
  • 4,566
  • 2
  • 36
  • 39
  • So there is one. Thank you. Can you add the link to the relevant page where you found it in the magnific documentation. – Graham Jul 23 '14 at 09:57
3

Here is simple solution from Magnific popup documentation

$('.image-link').on('mfpOpen', function(e /*, params */) {
  console.log('Popup opened',  $.magnificPopup.instance);
});
2

Old question, i know, but none of the other answers solved the same issue for me.

The next code solved it for me:

$('.open-popup-link').magnificPopup({
   callbacks: {
     open: function() {
       console.log('text to show in console if popup is open');
     }
   }
});
Mark
  • 6,762
  • 1
  • 33
  • 50