Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opening modal window from iFrame into parent window

I need some help appending a modal from an iFrame to it's parent body. I've heard about the jQuery plugin SimpleModal and even tried it, but failed.

So I have a page with an iFrame and inside this iFrame there is a button that should open a modal window in the parent window. The problem is that I don't have access to put code into the parent window. I just have access to the iFrame.

For any kind of help, I'm very thankful!

like image 388
user3548416 Avatar asked Mar 18 '23 01:03

user3548416


1 Answers

Without any example code, it's kinda hard to show you per your exact layout, but I can give you an example of how I've achieved this. Keep in mind, everything must be on the same domain, which I would assume it is.

I had to do this for a CRM I've developed and here's an example of how I did it:

parent HTML

<body>
    <div id="myModal">stuff</div>

parent JS

<script>
    $(function() {
        $('#myModal').someDialogPlug({ some: options });
    })
</script>

iFrame HTML

<button id="btnPopModal">click me</button>

iFrame JS

<script>
    $(function() {
        $('#btnPopModal').on('click', function(e) {
            //  here's the fun part, pay attention!
            var $body = $(window.frameElement).parents('body'),
                dlg = $body.find('#myModal');
            dlg.someDialogPlugin('open');
        });
    })
</script>
like image 155
SpYk3HH Avatar answered Mar 26 '23 01:03

SpYk3HH