把代码添加到后台/界面/网站第三方统计代码:
- <script>
- // 外部链接安全提示
- function jumpToExternalLink(link) {
- const message = '<e class="wot">您即将离开本站跳转到如下网址,该网址未在本站确认的安全范围内,请提前确认隐私安全后跳转。</e><p class="wot">即将访问:' + link + '</p>';
- showDialog(message, 'confirm', '即将访问外部链接', 'window.open(\'' + link + '\', \'_blank\')', 0, 2, '本站域名:bbs.boonkiong.com', '继续访问', '取消');
- }
-
- function forLinks() {
- // 获取页面中所有的链接元素
- const links = document.querySelectorAll('a, [data-href]');
-
- // 遍历每个链接元素,并为其绑定点击事件
- links.forEach((link) => {
- const href = link.getAttribute('href') || link.getAttribute('data-href');
-
- // 判断链接是否为外部链接
- if (href && href.startsWith('http') && !href.includes(window.location.host)) {
- link.addEventListener('click', (event) => {
- event.preventDefault();
- jumpToExternalLink(href);
- });
- link.setAttribute('target', '_blank'); // 在新窗口中打开链接
- }
- });
- }
- forLinks();
- </script>
复制代码
|