open modal window from iframe into the parent

后端 未结 2 1312
情书的邮戳
情书的邮戳 2021-01-01 00:18

I have a page with an iframe, and inside this iframe are some links that should open a modal window in the parent window. The thing is I dont have access to put code into th

相关标签:
2条回答
  • 2021-01-01 00:48

    Spend 1 day to open modal windows from iframe document first i did single case :

    parent.$("#you_modal_window_selector").css("visibility", "visible");
    

    !!! keyword changin matter is PARENT. (in small letters)

    Second i change all buttons in iframe included document with script:

    <script> 
     $(function() {
            $(".open-modal").on("click", function (e) {
                var $this = $(this),
                $href = $this.attr("href");
                e.preventDefault();
                parent.$($href).css("visibility", "visible");
                parent.$(".modal-window-dark").css("visibility", "visible");
            });
        });
    </script>
    
    0 讨论(0)
  • 2021-01-01 01:03

    You can use JQuery plugin SimpleModal

    There's an option called "appendTo", where you can tell where do you put your Modal. The only problem with that approach is that the modal's overlay appear with iframe's size, so you must give it your desired width and height after you open it.

    $('#div-modal').modal({
        appendTo: $(window.parent.document).find('body'),
        overlayCss: {backgroundColor:"#333"}, // Optional overlay style
        overlayClose:true, 
    });
    // Set overlay's width
    $(window.parent.document).find('#simplemodal-overlay').css('width', '100%');
    

    If the div you want to open as a modal is in your parent window, you could replace $('#div-modal') with $(window.parent.document).find('#div-modal')

    0 讨论(0)
提交回复
热议问题