Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Chrome中的后退按钮不';关闭fancybox iframe后无法正常工作_Jquery_Google Chrome_Fancybox - Fatal编程技术网

Jquery Chrome中的后退按钮不';关闭fancybox iframe后无法正常工作

Jquery Chrome中的后退按钮不';关闭fancybox iframe后无法正常工作,jquery,google-chrome,fancybox,Jquery,Google Chrome,Fancybox,不久前,我在fancybox github上发布了相同的问题,但当时这个问题无法解决,所以我想我应该在这里再试一次: 在Chrome中,我打开fancybox iframe,然后使用iframe页面上的链接导航,然后关闭fancybox。在关闭fancybox之后,为了返回,我需要按我在iframe页面上单击的链接数的倍来单击back按钮。所以我猜(仅在Chrome-FF中,即工作正常)我在fancybox iframe上所做的任何导航都会记录在开场白的历史记录中,导致一种非常奇怪的行为:当用户

不久前,我在fancybox github上发布了相同的问题,但当时这个问题无法解决,所以我想我应该在这里再试一次:

在Chrome中,我打开fancybox iframe,然后使用iframe页面上的链接导航,然后关闭fancybox。在关闭fancybox之后,为了返回,我需要按我在iframe页面上单击的链接数的倍来单击back按钮。所以我猜(仅在Chrome-FF中,即工作正常)我在fancybox iframe上所做的任何导航都会记录在开场白的历史记录中,导致一种非常奇怪的行为:当用户关闭fancybox并点击后退按钮时,同一页面会反复加载,直到超过iframe上的点击次数

以下是一个例子: 还有我用来打开fancybox的代码

$("#link").fancybox({
    'autoDimensions'    : true,
    'width'                         : 400,
    'height'                        : 300,
    'autoScale'                     : false,
    'type'              : 'iframe'
});
在fancybox iframe中打开站点,导航3-4次单击,然后关闭iframe。然后在结果窗格上尝试右键单击->返回,注意浏览器之间的不同行为-FF和IE会将您发送到上一个“opener”页面,而chrome只会按照您在iframe上单击链接的次数重新加载opener

如果没有解决方案,我也会对fancybox的一个很好的替代品感兴趣,它有iframe选项和类似的外观


谢谢

问题在于浏览器以不同的方式管理历史。据我所知,Opera和Safari也有同样的问题

一个棘手的解决办法是在fancybox打开时捕获当前的
历史。长度
,如果浏览器与Chrome、Opera和Safari匹配,则在关闭后恢复它(我不知道还有其他浏览器,但答案可以扩展)

使用上面的代码,我将添加一些回调,如:

var $history;
$("#link").fancybox({
    autoSize: true, //autoDimensions is an option for v1.3.4
    width: 400,
    height: 300,
    fitToView: false, //autoScale is an option for v1.3.4
    type: 'iframe',
    beforeLoad: function () {
        $history = window.history.length; // catch current history
    },
    afterClose: function () {
        if (navigator.userAgent.match(/(Chrome|Opera|Safari)/gi)) {
            var goTo = window.history.length - $history;
            window.history.go(-goTo) // restore initial history
        }
    }
});


注意:这适用于fancybox v2.1.x

这很有效-它也可以使用onStart和onClose回调在fancybox 1.3.4上使用。我还用很多类似的插件(如colorbox、lightbox等)测试了相同的情况,它们在Chrome中都有相同的问题行为,而在IE、FF中工作良好。所以,在找到真正的解决方案之前,这一切都很好。