How to open a magnific popup on page load?

Bruno Gomes picture Bruno Gomes · Sep 10, 2013 · Viewed 42k times · Source

I'm using Magnific Popup and I would like to have a video come up as soon as the page loads in a popup.

I got the plugin to work fine, but I have no idea on how to get it to pop up as soon as the page loads, without clicking on the thumbnail.

I looked around for a solution, but I did not manage to get it to work.

Answer

bbone picture bbone · Sep 10, 2013

If you're using jQuery you could just listen for the window load event and then call the open method for your Magnific Popup like so:

(function($) {
    $(window).load(function () {
        // retrieved this line of code from http://dimsemenov.com/plugins/magnific-popup/documentation.html#api
        $.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);
    });
})(jQuery);