Open popup from another function - Magnific Popup

Hassan Sardar picture Hassan Sardar · Feb 21, 2014 · Viewed 15.5k times · Source

I want to open my popup when ajaxCall function is called.

Like this:

function ajaxCall()
{

 openPopup();

}

function openPopup()
{

$('.popup-modal').magnificPopup({

type: 'inline',
modal: false,

});

$(document).on('click', '.closePopup', function (e) 
            {
                e.preventDefault();
                $.magnificPopup.close();
            });

}

Here is the fiddle: http://jsfiddle.net/qweWa/33/

I want this popup to open when ajaxCall function is called.

Here is the working fiddle for onclick button open popup:

http://jsfiddle.net/qweWa/27/

Answer

crafter picture crafter · Jan 20, 2015

Use the open() function

function openPopup(el) { // get the class name in arguments here
            $.magnificPopup.open({
                items: {
                    src: '#thanksModal',
                },
                type: 'inline'
            });
}

JSFiddle : http://jsfiddle.net/t5f5e5zw/2/