JS如何实现在微信中调用外部浏览器打开指定链接

使用方法,复制以下贴到index.php 顶部就可以了.
场景 比如网页包含视频播放  在QQ\WX打开QQ\WX直接调用自己的播放器播放,而且播放完成还有AD推送,非常恶心,所以有了以下代码有乱码的话说明你网页是GBK  自行转换下
 

 

 

 

  1. <?php
  2. function qqwx(){ 
  3.     if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
  4. echo '<!DOCTYPE html>
  5. <html>
  6.   <head>
  7.       <meta http-equiv="Content-Language" content="zh-CN">
  8.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  9.     <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0" />
  10.     <meta content="telephone=no" name="format-detection" />
  11.  
  12.     <title>提示</title>
  13.     
  14.     <style>
  15.         html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{line-height:1.6;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px}body,h1,h2,h3,h4,h5,p,ul,ol,dl,dd,fieldset,textarea{margin:0}fieldset,legend,textarea,input,button{padding:0}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;*font-family:"Helvetica Neue",Helvetica,Arial,sans-serif}ul,ol{padding-left:0;list-style-type:none;list-style-position:inside}a img,fieldset{border:0}a{text-decoration:none}
  16.  
  17.         body{
  18.             color:#222;
  19.             font-size: 12px;
  20.             padding: 120px 15px 20px;
  21.             text-align:center;
  22.         }
  23.         h3{ 
  24.             font-size: 18px; 
  25.             font-weight: normal;
  26.             margin-bottom: 13px;
  27.         }
  28.         .url{
  29.             padding: 5px 0;
  30.             word-break:break-all;
  31.         }
  32.     </style>
  33.   </head>
  34.   <body url="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'">
  35.     <div class="">
  36.         <h3>请长按网址复制后使用浏览器访问</h3>
  37.         <div id="url" class="url"></div>
  38.     </div>
  39.     <script>
  40.         var text = document.createTextNode(document.body.getAttribute("url").replace(/&/g, "&"));
  41.         document.getElementById("url").appendChild(text);
  42.     </script>
  43.   </body>
  44. </html>';
  45. exit();     }    
  46.         if ( strpos($_SERVER['HTTP_USER_AGENT'], 'QQ/') !== false ) {
  47. echo '<!DOCTYPE html>
  48. <html>
  49.   <head>
  50.   
  51.     <script src="https://open.mobile.qq.com/sdk/qqapi.js?_bid=152"></script>
  52.   <script type="text/javascript"> mqq.ui.openUrl({ target: 2,url: "http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'"}); </script>
  53.     <meta http-equiv="Content-Language" content="zh-CN">
  54.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  55.     <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0" />
  56.     <meta content="telephone=no" name="format-detection" />
  57.  
  58.     <title>提示</title>
  59.     
  60.     <style>
  61.         html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{line-height:1.6;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px}body,h1,h2,h3,h4,h5,p,ul,ol,dl,dd,fieldset,textarea{margin:0}fieldset,legend,textarea,input,button{padding:0}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;*font-family:"Helvetica Neue",Helvetica,Arial,sans-serif}ul,ol{padding-left:0;list-style-type:none;list-style-position:inside}a img,fieldset{border:0}a{text-decoration:none}
  62.  
  63.         body{
  64.             color:#222;
  65.             font-size: 12px;
  66.             padding: 120px 15px 20px;
  67.             text-align:center;
  68.         }
  69.         h3{ 
  70.             font-size: 18px; 
  71.             font-weight: normal;
  72.             margin-bottom: 13px;
  73.         }
  74.         .url{
  75.             padding: 5px 0;
  76.             word-break:break-all;
  77.         }
  78.     </style>
  79.   </head>
  80.   <body url="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'">
  81.     <div class="">
  82.         <h3>如需浏览,请长按网址复制后使用浏览器访问</h3>
  83.         <div id="url" class="url"></div>
  84.     </div>
  85.     <script>
  86.         var text = document.createTextNode(document.body.getAttribute("url").replace(/&/g, "&"));
  87.         document.getElementById("url").appendChild(text);
  88.     </script>
  89.   </body>
  90. </html>';
  91. exit();
  92.     }  
  93. }
  94. qqwx();
  95. ?>

复制代码

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
微信端或外部浏览器通过H5链打开微信小程序是通过特殊的URL链实现的。首先,在微信小程序的开发者工具,我们需要设置小程序的相关参数,并获取到小程序的AppID。然后,在H5页面,通过以下方式使用URL链打开微信小程序。 1. 微信打开微信小程序:我们可以在H5页面创建一个按钮,当用户点击按钮时,触发打开微信小程序的操作。代码如下所示: ```html <button onclick="openMiniProgram()">打开微信小程序</button> <script> function openMiniProgram() { window.location.href = "weixin://dl/business/?t=abcde12345"; // 将abcde12345替换为你的AppID } </script> ``` 2. 外部浏览器打开微信小程序:我们可以通过微信开放平台的跳转链功能,生成一个特殊的URL链,用户在浏览器打开该链后,会跳转到微信客户端并打开指定微信小程序。代码如下所示: ```html <button onclick="openMiniProgram()">打开微信小程序</button> <script> function openMiniProgram() { window.location.href = "https://mp.weixin.qq.com/mp/wapopen?username=gh_abcdefgh1234"; // 将gh_abcdefgh1234替换为你的小程序原始ID } </script> ``` 通过上述方式,用户在微信端或外部浏览器点击相应的按钮,即可打开指定微信小程序。在链,我们可以根据需要传递一些参数,以在小程序进行相应的操作,实现更丰富的功能和交互体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值