BoonKiong.com2026™

人气 13

外部链接安全提示 [复制链接]

boonkiong 网站创始人认证 网站管理员认证 前天 18:33

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>
复制代码



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

您还未登录

随手拍~~:

热度会员~~:

boonkiongadminJustinIromsbka文強無名无名

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

GMT+8, 2026-7-23 04:20 , Processed in 0.025286 second(s), 25 queries .

Powered by Discuz! X3.5  © 2001-2026 Discuz Team.