In the end implemented in mobile web browser and click the button to copy the text (and test micro open letter APP)

On the IOS phones tested the following browsers, links:

Open micro letter: Baidu browser, Sogou browser , Sogou search, opening the link in a nail

Hit the open micro-channel: the UC browser, QQ browser, Chrome browser, Safari browser, browser 360, Firefox browser, browser E (Soft), aoyou browser, R browser, the browser +

 

html:

<span style="display:none;" id="linkCopy">复制的内容</span>
<p class="copy" id="btnWechat" style="display:inline-block;padding:3px 8px;border: 1px solid #333;" >点我</p>

script:

 <script>
    // 浏览器判断
    var browser = {
       versions: function() {
          var u = navigator.userAgent;
          return {
             trident: u.indexOf('Trident') > -1,    // IE内核
             presto: u.indexOf('Presto') > -1,      // opera内核
             webKit: u.indexOf('AppleWebKit') > -1, // 苹果、谷歌内核
             gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, // 火狐内核
             mobile: !!u.match(/AppleWebKit.*Mobile.*/),            // 移动终端
             ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),      // ios终端
             android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, // android终端或者uc浏览器
             iPhone: u.indexOf('iPhone') > -1,  // iPhone或者QQHD浏览器
             iPad: u.indexOf('iPad') > -1,       // iPad
             webApp: u.indexOf('Safari') == -1,   // web应用程序
             souyue: u.indexOf('souyue') > -1,
             superapp: u.indexOf('superapp') > -1,
             weixin:u.toLowerCase().indexOf('micromessenger') > -1,
             Safari:u.indexOf('Safari') > -1
          };
      }(),
           language: navigator.language.toLowerCase()
   };
   // 点击
   $('#btnWechat').click(function () {
      var tVal = $('#linkCopy').text();
      var cpInput = document.createElement('input'); //创建一个对象
      cpInput.value = tVal;
      document.body.appendChild(cpInput); //appendChild()方法在节点的子节点末添加新的子节点
      cpInput.select();  //选择对象
      document.execCommand("Copy"); //执行浏览器复制命令
      cpInput.className = 'cpInput';
      cpInput.style.display='none';
      alert("复制成功,在微信搜索处粘贴即可");
      // ios、android
      if (browser.versions.ios) {
          window.location.href = 'weixin://';
      }else if (browser.versions.android){
          var ifr = document.createElement("iframe");
          ifr.src = 'weixin://';
          ifr.style.display = "none";
          document.body.appendChild(ifr);
      }
   });
</script>

 

Published 52 original articles · won praise 15 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_41408081/article/details/105251808