最近网盘拉新又有了新的规则,只有手机端转存和拉新才有收益,而我的其它网站大部分都是手机转存,只能提醒用户用手机来访问网站了。
做法很简单,就是当用户在电脑上点击网盘链接时会弹出提示,要求用户去用手机打开网站文章访问网盘链接,手机端点击网盘链接则可以直接转存。
代码如下。
代码一
<style> /* 模态框样式 */ #myModal { display: none; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4); padding-top: 60px; } .modal-content { background-color: #fefefe; margin: 5% auto; padding: 20px; border: 1px solid #888; width: 80%; } .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; } </style> <p> <a href="https://www.125116.com/wp-content/themes/puock/inc/go.php?to=aHR0cHM6Ly9wYW4ucXVhcmsuY24=">访问 pan.quark.cn</a><br> <a href="https://www.125116.com/wp-content/themes/puock/inc/go.php?to=aHR0cHM6Ly9leGFtcGxlLmNvbQ==">访问其他网站</a><br> <a href="https://www.125116.com/wp-content/themes/puock/inc/go.php?to=aHR0cHM6Ly9hbm90aGVyLWRvbWFpbi5jb20=">访问 another-domain.com</a> </p> <!-- 模态框 --> <div id="myModal"> <div class="modal-content"> <span class="close">×</span> <p>需要手机端访问点击才能进入</p> </div> </div> <script> document.addEventListener('DOMContentLoaded', function() { const targetDomains = ['pan.quark.cn', 'another-domain.com']; // 需要匹配的多个域名 function isMobile() { return /Mobi|Android/i.test(navigator.userAgent); } const links = document.querySelectorAll('a'); links.forEach(link => { // 检查链接是否包含任意一个目标域名 if (targetDomains.some(domain => link.href.includes(domain))) { link.addEventListener('click', function(event) { if (!isMobile()) { event.preventDefault(); // 阻止默认行为 document.getElementById('myModal').style.display = "block"; // 显示模态框 } }); } }); // 关闭模态框 const span = document.getElementsByClassName("close")[0]; span.onclick = function() { document.getElementById('myModal').style.display = "none"; // 隐藏模态框 } // 点击模态框外部关闭模态框 window.onclick = function(event) { const modal = document.getElementById('myModal'); if (event.target == modal) { modal.style.display = "none"; // 隐藏模态框 } } }); </script>
代码2
<style> /* 模态框样式 */ #myModal { display: none; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4); padding-top: 60px; } .modal-content { background-color: #fefefe; margin: 15% auto; padding: 20px; border: 1px solid #888; width: 80%; text-align: center; } .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; } </style> <p> <a href="https://www.125116.com/wp-content/themes/puock/inc/go.php?to=aHR0cHM6Ly9kb21haW4xLmNvbQ==">访问域名1</a><br> <a href="https://www.125116.com/wp-content/themes/puock/inc/go.php?to=aHR0cHM6Ly9kb21haW4yLmNvbQ==">访问域名2</a><br> <a href="https://www.125116.com/wp-content/themes/puock/inc/go.php?to=aHR0cHM6Ly9kb21haW4zLmNvbQ==">访问域名3</a><br> <a href="https://www.125116.com/wp-content/themes/puock/inc/go.php?to=aHR0cHM6Ly9leGFtcGxlLmNvbQ==">访问其他网站</a> </p> <!-- 模态框 --> <div id="myModal"> <div class="modal-content"> <span class="close">×</span> <p>需要手机端访问点击才能进入</p> </div> </div> <script> function isMobile() { // 简单的移动设备检测 return /Mobi|Android/i.test(navigator.userAgent); } function handleLinkClick(event, url) { if (!isMobile()) { event.preventDefault(); // 阻止默认链接行为 document.getElementById('myModal').style.display = "block"; // 显示模态框 } else { window.location.href = url; // 手机端正常访问 } } document.addEventListener("DOMContentLoaded", function() { // 获取所有链接 const links = document.querySelectorAll("a"); // 遍历链接 links.forEach(link => { const url = link.href; // 检查链接是否包含指定的域名 if (url.includes("domain1.com") || url.includes("domain2.com") || url.includes("domain3.com")) { link.onclick = function(event) { handleLinkClick(event, url); }; } }); // 关闭模态框 const span = document.getElementsByClassName("close")[0]; span.onclick = function() { document.getElementById('myModal').style.display = "none"; // 隐藏模态框 } // 点击模态框外部关闭模态框 window.onclick = function(event) { const modal = document.getElementById('myModal'); if (event.target == modal) { modal.style.display = "none"; // 隐藏模态框 } } }); </script>
正文完