You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Fancybox 5.0.36中打开iframe时禁用URL中的#锚点

解决方案

要阻止Fancybox向URL插入#锚点,同时保留data-fancybox='ViewFriend'的设置,只需在Fancybox绑定配置中添加hash: false选项即可,这个配置在v5中同样适用,无需大幅调整原有代码。

修改后的代码示例

<a href='/profile_friends_add.php?FriendID=1'  
    class='btn btn-xs btn-primary btn-shadow '
    data-fancybox='ViewFriend'
    data-type='iframe'  data-preload='false' data-width='500' data-height='310' >
    View Friend 1</a>

<a href='/profile_friends_add.php?FriendID=2'  
    class='btn btn-xs btn-primary btn-shadow '
    data-fancybox='ViewFriend'
    data-type='iframe'  data-preload='false' data-width='500' data-height='310' >
    View Friend 2</a>

<script>
Fancybox.bind('[data-fancybox="ViewFriend"]', {
        groupAttr: false,
        type: 'iframe',
        hash: false, // 新增此配置,阻止URL添加锚点
        
        on: {
            close: (fancybox) => {
                console.log(fancybox.options.triggerEl);
                console.log("On Close: ViewFriend");
                
                window.location.reload();
                //location.href = 'profile_friends.php';
            },
        },
    });
</script>

说明

  • hash: false会禁用Fancybox的URL hash同步功能,弹窗弹出时不再修改URL的锚点部分,也就避免了页面重载后因残留锚点再次触发弹窗的问题。
  • 该配置在Fancybox v3和v5中均有效,你的原有逻辑无需其他调整,只需添加这一行配置即可满足需求。

内容的提问来源于stack exchange,提问作者user9731

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 00:12:04