call Fancybox in parent from iframe

后端 未结 3 1489
暗喜
暗喜 2020-11-22 16:53

I have 2 pages, my index.html and social.html. I cleaned out my index and left only the jquery code need for fancybox What I am trying to do is to have images inside social.

3条回答
  •  [愿得一人]
    2020-11-22 17:17

    Since the img is on an iframe is a different webpage. So Jquery is on index.html but the img doesnt, thats why JQuery cant get to the image.

    Maybe using something like this... But i dont think it would work

    On index.html script part

    $(document).ready(function () {
        //function to active fancybox on the thumbs class inside the iframe
        //Not sure it works on iframes, probably it doesnt.
        $("#iframeID.thumbs").fancybox();
    });
    

    And add the id to the iframe declaration < iframe src=\"social.html\" id="iframeID" etc... rest of properties>

    But, my advice is to use divs instead of iframes. You also should remove the onclick from the image for non-obstrusive Javascript.

    Check the tutorial: http://fancybox.net/howto If you want a similar tutorial in spanish you can check my site too.

提交回复
热议问题