Fancybox - Opening a link inside a fancybox into the same fancybox?

独自空忆成欢 提交于 2020-01-15 03:40:15

问题


On my site I have a fancybox that contains the contents of a hidden <div> on the page. This hidden <div> contains a link to an external site.

Is it possible to have this link open in the already open fancybox?

The code I currently have is as follows:

$("#lightbox-link").fancybox({
    'scrolling' : 'no',
    'width': 5000, 
    'height': 2000,
    'onComplete': function() { 
        $('a#yes').click(function() {
            $.cookie("survey", "dismissed", {expires: 365});
            $.fancybox.close();
        });
        $('a#no').click(function() {
            $.cookie("survey", "big-snooze", {expires: 14});
            $.fancybox.close();
        });
        $('a#later').click(function() {
            $.cookie("survey", "snooze", {expires: 1});
            $.fancybox.close();
        });
    },
    'content' : $("#lightbox-content").html()
});

Thanks!


回答1:


Fancybox's built-in 'href' attribute loads content relative to the current website. As a result loading an external web page shows missing graphics. I came up with the following solution using an iframe. The transition to the external website appears nice and smooth.

<script type="text/javascript">
    $(function () {   //jquery onload
        $.fancybox('<div id="myfancy"><a href="#" onclick="javascript:openlink(\'http://www.cleversavers.com\');">Click me</a></div>'
            , {});
    });
    function openlink(url) {
        $.fancybox('<iframe id="myi" src="' + url + '" frameborder="0" height="400" width="600" />', {});
    }
</script>


来源:https://stackoverflow.com/questions/5389412/fancybox-opening-a-link-inside-a-fancybox-into-the-same-fancybox

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