搜索
查看: 8514|回复: 0

网站在微信打开强制自动跳到外部浏览器防红代码

[复制链接]

839

主题

0

回帖

3040

积分

管理员

积分
3040
发表于 2024-12-12 16:44:59 | 显示全部楼层 |阅读模式




可以直接拉起微信浏览器跳转到外部的浏览器,原理是模拟下载文件拉起外部浏览器跳转,这个方式只测试过PC和安卓手机可以用。




  1. <?php
  2. $ua =$_SERVER['HTTP_USER_AGENT'];
  3. $isWechat = (strpos($ua, 'MicroMessenger')) ? true : false;
  4. if ($isWechat) {
  5.     header("Content-Disposition: attachment; filename="a.doc"");
  6.     header("Content-Type: application/vnd.ms-word; charset=utf-8");
  7. } else {
  8.     header('location: http://yourdomain');
  9. }
  10. ?>
  11. <!DOCTYPE html>

  12. <html lang="zh">
  13. <head>
  14. <meta charset="UTF-8">
  15. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  16. <title>浏览器打开</title>
  17. <style>
  18.   body {
  19.     font-family: 'Arial', sans-serif;
  20.     background-color: #f7f7f7;
  21.     text-align: center;
  22.     padding-top: 50px;
  23.   }

  24.   .container {
  25.     margin: 0 auto;
  26.     width: 90%;
  27.     max-width: 600px;
  28.     background-color: #fff;
  29.     padding: 20px;
  30.     box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  31.     border-radius: 8px;
  32.   }

  33.   button {
  34.     background-color: #007bff;
  35.     color: white;
  36.     padding: 10px 20px;
  37.     font-size: 18px;
  38.     border: none;
  39.     border-radius: 5px;
  40.     cursor: pointer;
  41.     margin-top: 20px;
  42.   }

  43.   button:hover {
  44.     background-color: #0056b3;
  45.   }

  46.   .instructions {
  47.     margin-top: 20px;
  48.     font-size: 16px;
  49.     color: #666;
  50.   }
  51. </style>

  52. <script>
  53. function openInBrowser() {
  54.   var targetUrl = 'http://yourdomain'; // 替换为您想要跳转的网址

  55.   // 检测是否在微信浏览器中
  56.   var ua = navigator.userAgent.toLowerCase();
  57.   if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  58.     // 在微信内,显示提示信息
  59.     alert('请点击右上角菜单,选择"在浏览器中打开"');
  60.   } else {
  61.     // 不在微信内,直接跳转
  62.     window.location.href = targetUrl;
  63.   }
  64. }
  65. </script>
  66. </head>
  67. <body>

  68. <div class="container">
  69.   <h1>酷库博客</h1>
  70.   <p>为了更好浏览体验,请通过右上角从浏览器打开</p>
  71.   <div class="instructions">
  72.     <p>如果您在微信中打开此页面,请:</p>
  73.     <ol>
  74.       <li>点击页面右上角的三个点</li>
  75.       <li>选择“在浏览器中打开”</li>
  76.       <li><button onclick="openInBrowser()">打开网站</button></li>
  77.     </ol>
  78.   </div>
  79. </div>
  80. </body>
  81. </html>
复制代码


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

本版积分规则

Powered by :Cc娱乐社区

Archiver|手机版|小黑屋|

今天是:|本站已经安全运行: