function openWx(){
locatUrl = "weixin://";
if(/ipad|iphone|mac/i.test(navigator.userAgent)) {
var ifr =document.createElement("iframe");
ifr.src = locatUrl;
ifr.style.display = "none";
document.body.appendChild(ifr);
}else{
window.location.href = locatUrl;
}
}
最近在做一個手機站,要求點擊分享可以直接打開微信分享出去。而不是jiathis,share分享這種的點擊出來二維碼。在網上看了很多,都說APP能喚起微信,手機網頁實現不了。也找了很多都不能直接喚起微信。
總結出來一個可以直接喚起微信的。適應手機qq瀏覽器和uc瀏覽器。
下面上代碼,把這些直接放到要轉發的頁面里就可以了:
html部分:
<script src="mshare.js"></script>//引進mshare.js
<button data-mshare="0">點擊彈出原生分享面板</button>
<button data-mshare="1">點擊觸發朋友圈分享</button>
<button data-mshare="2">點擊觸發發送給微信朋友</button>
js部分:
<script>
var mshare = new mShare({
title: 'Lorem ipsum dolor sit.',
url: 'http://m.ly.com',
desc: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quaerat inventore minima voluptates.',
img: 'http://placehold.it/150x150'
});
$('button').click(function () {
// 1 ==> 朋友圈 2 ==> 朋友 0 ==> 直接彈出原生
mshare.init(+$(this).data('mshare'));
});
原文:https://blog.csdn.net/qq_18976087/article/details/79095735
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!