Manuel Jordan
Manuel Jordan

Reputation: 16271

Close a popup modal window of iframe type through a button

I have a parent page and child page sharing the same file.js file for jquery events.

Well I am working with Magnific Popup and I have:

$("#addDetailButton").magnificPopup({
        items: {
              src: 'someURL'
        },
        type: 'iframe',
        enableEscapeKey: false,
        modal: true

});

My popup is based on iframe and is modal. How I can close the modal window with a button html element? I did a research on StackOverflow and all the replies and based in inline type.

I have tried

<input id="cancel" type="button" value="Cancel"/> // child page

$("#cancel").click(function(){
        $.magnificPopup.close();
});

and I always receive trough Firefox's Web Console the following:

TypeError: $.magnificPopup is undefined

Thank You

Upvotes: 1

Views: 3344

Answers (1)

Sebastian Stiehl
Sebastian Stiehl

Reputation: 1888

A Iframe has its own scope it can't access the surrounding scope directly. But you can step up in the main window with the parent global variable.

Try this:

parent.$.magnificPopup.close();

You can find more on this topic here: Calling a parent window function from an iframe

Upvotes: 2

Related Questions