js一键复制微信号,强制跳转到微信

pc加手机端一键复制,兼容安卓和ios,强制跳转到微信


image


 image


微信号:<span class="copy"><span class="copyarticle">w252439581</span></span>


<script>

$(".copy").click(function () {

    $('#article').attr('id','');

    $(this).find('.copyarticle').attr('id','article');

    $('#copy').click();

});



 function copyArticle(event){

 const range = document.createRange();

 range.selectNode(document.getElementById('article'));

 const selection = window.getSelection();

 if(selection.rangeCount > 0) selection.removeAllRanges();

 selection.addRange(range);

 document.execCommand('copy');

       var locatUrl = "weixin://";

  if (/ipad|iphone|mac/i.test(navigator.userAgent)) {

  alert("点击复制微信号到微信添加",1500);     

  var ifr = document.createElement("iframe");

      

  ifr.src = locatUrl;

  ifr.style.display = "none";

  document.body.appendChild(ifr);

  }else{

  window.location.href = locatUrl;

  }

 }

document.getElementById('copy').addEventListener('click', copyArticle, false);


      

    </script>


微信扫码咨询
建站咨询
cache
Processed in 0.006260 Second.