question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Open() method doesn't work for the dynamic popups

See original GitHub issue

// Open popup immediately. If popup is already opened - it’ll just overwite the content (but old options will be kept). // - first parameter: options object // - second parameter (optional): index of item to open $.magnificPopup.open({ items: { src: ‘someimage.jpg’ }, type: ‘image’

// You may add options here, they’re exactly the same as for $.fn.magnificPopup call // Note that some settings that rely on click event (like disableOn or midClick) will not work here }, 0);

This doesn’t work for a dynamically created popups.

Here’s an example http://jsbin.com/esebEGa/1

Child static works well:

$('.toggle').each(function() {
  var item = $(this);
  var decor = item.data('mfp-decor');

  item.magnificPopup({
    type: 'inline',
    midClick: true,
    removalDelay: 400,
    mainClass: function() {
      var classname = 'mfp-fade';

      if (decor && decor.length) {
        classname = classname + ' ' + decor;
      }

      return classname;
    }
  });
});

Child dymanic doesn’t work:

$('.dynamic').on('click', function(event) {
    event.preventDefault();

      $.magnificPopup.open({
            items: {
              src: '<div class="popup popup-status">Dynamic</div>'
            },
            type: 'inline',
            showCloseBtn: false,
            removalDelay: 400,
            mainClass: 'mfp-status'
          });
});

If child dymanic link is clicked, both popups are closed.

I’ve also tried this solution https://github.com/dimsemenov/Magnific-Popup/issues/53#issuecomment-17804411 - same result, both popups are closed once you try to open a dynamically created popup.

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dimsemenovcommented, Oct 1, 2013

Thank you, I’ll look into it.

By the way, to fix this you may just add event.stopImmediatePropagation(); on that .dynamic click event handler, so the event won’t come to popup at all.

0reactions
nvontrothacommented, Oct 26, 2016

Has there been any update on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Popups and window methods - The Modern JavaScript Tutorial
A popup can be opened by the open(url, name, params) call. It returns the reference to the newly opened window. Browsers block open...
Read more >
jQuery 'on' not registering in dynamically generated modal ...
Here is my new solution: Capture click events on my modal dialog, which, although it does not have any content when the event...
Read more >
popup('open') not working after navigate next page
1) My start up page is 1.aspx and i am using .popup('open') on this page and popup working fine. 2) I navigate to...
Read more >
How to Handle Alerts/Popups in Selenium WebDriver
1) void dismiss() – The dismiss() method clicks on the “Cancel” button as soon as the pop up window appears. 2) void accept()...
Read more >
Open javascript popup in WKWebView? - Apple Developer
I have a WKWebView in my app which opens a page where there is a button that ... links to open, but I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found