简体   繁体   English

Fancybox递归导致堆栈溢出

[英]Fancybox Recursion causes a stack overflow

It seems that when I add an afterClose callback to my fancybox I'm getting this error: 看来,当我在我的fancybox中添加afterClose回调时,出现此错误:

Uncaught RangeError: Maximum call stack size exceeded 未捕获的RangeError:超出最大调用堆栈大小

This is the code I am using: 这是我正在使用的代码:

$("a.termsLink").fancybox({
    type            : 'iframe', 
    fitToView       : false,
    width           : 450,
    height          : 600,
    afterClose  : function(){
        $('#regForm').click();
    }
});

What is supposed to happen is when the termsLink box closes, the regForm is supposed to open. 应该发生的情况是,当termsLink框关闭时,regForm应该打开了。 I've expiremented with differnt callbacks, but the issue that I am running into seems to be unaffected by this. 我已经用不同的回调过期了,但是我遇到的问题似乎不受此影响。

The solution appears to be as follows: 解决方案如下所示:

    afterClose      : function(){
        setTimeout(function(){$('#regForm').click();}, 1);
    }

However that feels like a very hacky method to me, the issue seems to be that the fancybox code trys to call the new box while the animation for the other box is still running, which causes this issue. 但是,这对我来说似乎是一种非常笨拙的方法,问题似乎是,fancybox代码尝试在另一个框的动画仍在运行时调用新框,从而导致了此问题。 Is this a documented issue with FancyBox? 这是FancyBox的记录问题吗? Or is this a function of the way jQuery animation event work? 还是这是jQuery动画事件工作方式的功能? Is there a more elegant solution to this issue? 有没有更优雅的解决方案?

If you're using Twitter Bootstrap < 2.3.1, it's known to cause this exact issue (I just experienced it, and upgrading bootstrap solved the problem) 如果您使用的是Twitter Bootstrap <2.3.1,则已知会导致此确切问题(我刚刚遇到过,升级引导程序即可解决该问题)

More details here: https://github.com/fancyapps/fancyBox/issues/519 此处有更多详细信息: https : //github.com/fancyapps/fancyBox/issues/519

Are you sure the problem is related to the click function? 您确定问题与点击功能有关吗? I found the same problem including, by mistake, two jQuery versions (jquery-1.2.6.pack.js and jquery-1.4.4.min.js) Removing the last one solved the problem. 我发现了相同的问题,包括错误地使用了两个jQuery版本(jquery-1.2.6.pack.js和jquery-1.4.4.min.js)。删除最后一个版本可以解决此问题。 I checked this because of this topic loading jquery twice causes an error? 我检查此内容是因为此主题两次加载jquery会导致错误? . You could try to check it. 您可以尝试检查它。

Try 尝试

$("a.termsLink").fancybox({
    type            : 'iframe', 
    fitToView       : false,
    width           : 450,
    height          : 600,
    afterClose  : function(){
        $('#regForm').focus();
    }
});

although what you have should work you're right. 尽管您所拥有的应该可以工作,但是您是对的。 Unsure but check the script doesn't close all fancybox's open. 不确定但请检查脚本是否不会关闭所有fancybox的打开状态。 if the #regForm is being opened into a fancybox hence why you'd need the timeout. 如果#regForm被打开到了一个花哨的盒子中,那么为什么您需要超时。

Looking into the fancybox script they use this function 查看fancybox脚本,他们使用此功能

    function _cleanup() {
        overlay.fadeOut('fast');

        title.empty().hide();
        wrap.hide();

        $.event.trigger('fancybox-cleanup');

        content.empty();

        currentOpts.onClosed(currentArray, currentIndex, currentOpts);

        currentArray = selectedOpts = [];
        currentIndex = selectedIndex = 0;
        currentOpts = selectedOpts  = {};

        busy = false;
    }

This basically confirms what I was saying before. 这基本上证实了我之前所说的内容。 All the instances of fancybox are cleared after this function is run. 运行此功能后,将清除所有fancybox实例。 So even though you've got one opening straight after it's being cleared before really being shown. 因此,即使您在真正显示之前先清除了一个开口。 The solution you've come up with seems to be the better solution unless you want to fiddle with the fancybox script yourself :) 除非您想自己摆弄fancybox脚本,否则您想出的解决方案似乎是更好的解决方案:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM