Open fancybox 3 into iframe parent

烈酒焚心 提交于 2019-12-20 05:44:23

问题


Here is my problem : - i have an fancybox 3 gallery intro an iframe - when i click to one of the link, i would like the image showing on top of the parent of my iframe

I have made many researches and tried several solutions

I found this : call Fancybox in parent from iframe but it only provide a solution for fancybox 2

Here is my code on the iframe :

$(document).ready(function() {
    parent.$(".fancybox").fancybox({
        href:  this.href
    });
});

Please note

  • i have included jquery and fancybox 3 both in the iframe and the parent

  • fancybox works like a charm independently in the iframe and the parent, but cannot be called from the iframe to be displayed in the parent (my problem)

  • i have also tried :

    $(".fancybox", top.document).fancybox

    $(".fancybox", window.opener.document).fancybox

    $(".fancybox", window.parent.document).fancybox

None of these worked

Thank you very much for your attention


回答1:


I hope you red the docs while doing "many researches". From the docs:

To access and control fancybox in parent window from inside an iframe:

// Adjust iframe height according to the contents
parent.jQuery.fancybox.getInstance().update();

This should give you a clue that you can use parent.jQuery.fancybox to use API from the parent page.

Then, API section should give you a clue how to open image gallery programmatically:

$.fancybox.open([
    {
        src  : '1_b.jpg',
        opts : {
            caption : 'First caption',
            thumb   : '1_s.jpg'
        }
    },
    {
        src  : '2_b.jpg',
        opts : {
            caption : 'Second caption',
            thumb   : '2_s.jpg'
        }
    }
], {
    loop : false
});

So, combining these two snippets should give you the answer.



来源:https://stackoverflow.com/questions/49580013/open-fancybox-3-into-iframe-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!