Hassan Sardar
Hassan Sardar

Reputation: 4523

Open popup from another function - Magnific Popup

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/

Upvotes: 4

Views: 17364

Answers (4)

crafter
crafter

Reputation: 6296

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/

Upvotes: 7

Jai
Jai

Reputation: 74738

You have to pass the class name of clicked button in the function:

function openPopup(el) { // get the class name in arguments here
   $('.'+el).magnificPopup({ // use it here
      type: 'inline',
      modal: false
   });
}

$(function () {
   $('.ajax-call').click(function (e) {
      openPopup(this.className); //<----pass the clicked button's class name
   });
   $(document).on('click', '.closePopup', function (e) {
      e.preventDefault();
      $.magnificPopup.close();
   });
});

Demo Fiddle

Upvotes: 3

Dimag Kharab
Dimag Kharab

Reputation: 4519

Try this

function openPopup()
        {

            $('.ajax-call').magnificPopup({

            type: 'inline',
            modal: true,

        });

        /*$.magnificPopup({



 type: 'inline',
        modal: false,

    });*/

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

    }

Upvotes: 0

Java_User
Java_User

Reputation: 1321

magnificPopup is not a function error. Please include any custom js files in your header section.

Upvotes: 0

Related Questions