查看: 101|回复: 0

外部链接安全提示

[复制链接]
  • TA的每日心情
    奋斗
    12 小时前
  • 签到天数: 9 天

    [LV.3]偶尔看看II

    1829

    主题

    66

    回帖

    5340

    积分

    管理员

    🤝 贡献
    3
    🌟 威望
    0
    🪙 金币
    3442
    💎 社区币
    146

    管理员帅哥金牛座羊

    发表于 2026-7-21 18:33:38 | 查看全部 |阅读模式

    1.jpg


    把代码添加到后台/界面/网站第三方统计代码:

    1. <script>
    2.     // 外部链接安全提示
    3.     function jumpToExternalLink(link) {
    4.       const message = '<e class="wot">您即将离开本站跳转到如下网址,该网址未在本站确认的安全范围内,请提前确认隐私安全后跳转。</e><p class="wot">即将访问:' + link + '</p>';
    5.       showDialog(message, 'confirm', '即将访问外部链接', 'window.open(\'' + link + '\', \'_blank\')', 0, 2, '本站域名:bbs.boonkiong.com', '继续访问', '取消');
    6.     }
    7.    
    8.     function forLinks() {
    9.     // 获取页面中所有的链接元素
    10.     const links = document.querySelectorAll('a, [data-href]');
    11.    
    12.     // 遍历每个链接元素,并为其绑定点击事件
    13.     links.forEach((link) => {
    14.       const href = link.getAttribute('href') || link.getAttribute('data-href');
    15.    
    16.       // 判断链接是否为外部链接
    17.       if (href && href.startsWith('http') && !href.includes(window.location.host)) {
    18.         link.addEventListener('click', (event) => {
    19.           event.preventDefault();
    20.           jumpToExternalLink(href);
    21.         });
    22.         link.setAttribute('target', '_blank'); // 在新窗口中打开链接
    23.       }
    24.     });
    25.     }
    26.     forLinks();
    27. </script>
    复制代码



    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|网站地图|文强阁

    相关侵权、举报、投诉及建议等,请发 E-mail:hsbk@hotmail.com

    Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

    在本版发帖