0

I am having an issue with FancyBox and its probably really simple to fix but I can't figure it out. I have a link and when the link it clicked, I want it to open external page. But the problem is the link just refreshes the current FancyBox, and never opens the other page. Here is my code:

$("#preview-box").html('<a href="http://www.google.com" target="_blank" >Go To Original</a><iframe sandbox="allow-forms allow-scripts" src="http://www.yahoo.com" width="100%" height="100%" style="min-height: 500px;"></iframe>');

$('#preview-box').fancybox({
    autoSize: false,
    width: '80%',
    height: '80%',
    onClosed: function () {
        $("#preview-box").empty();
    },
    afterClosed: function () {
        $("#preview-box").empty();
    }
}).trigger('click');

My question is why isn't the new link opening up in a new tab and just refreshing the current content, and how can I get this to work?

4

1 回答 1

2

我读你的代码太快了,投票决定将你的问题作为重复而关闭,对不起:(

您遇到的真正问题是您处于一个循环中:您将 fancybox 绑定到 ( #preview-box) 的选择器与 fancybox 所针对的选择器相同......所以每次您单击 fancybox 内的链接(显示内容#preview-box) 相同的选择器在fancybox 中被再次调用。

你应该把你的代码改成这个

$("#preview-box").html('<a href="http://www.google.com" target="_blank" >Go To Original</a>');

$.fancybox({
    href: "#preview-box",
    autoSize: false,
    width: '80%',
    height: '80%',
    afterClose: function () {
        $("#preview-box").empty();
    }
});

我删除了不必要的、过时的或错误的代码,例如iframeonClosedAPI 选项。

JSFIDDLE

于 2013-06-10T00:03:31.667 回答