微信內置的瀏覽器裏添加了WeixinJSBridge對象,可以通過引對象將內容分享到朋友圈,所以以下代碼只在微信內置瀏覽器中有效。
var?shareToWeixinFriend?=?function(data,?cb){
if?(typeof?WeixinJSBridge?==?'undefined')?{
return?false;
}
else?{
WeixinJSBridge.invoke('shareTimeline',?{
'img_url':?data.imgurl?||?'',?//?圖片url地址
'link':?data.url,?//?文章地址,此內容分享到朋友圈後可以點擊跳轉到此地址
'desc':?data.desc,
'title':?data.title
},?function(d)?{
//?返回res.err_msg取值,d還有壹個屬性是err_desc
//?share_timeline:cancel?用戶取消
//?share_timeline:fail 發送失敗
//?share_timeline:confirm?發送成功
WeixinJSBridge.log(d.err_msg);
cb?&&?cb(d.err_msg);
});
}
return?false;
}
另外在微信內置瀏覽器中可以通過weixin://鏈接直接查看某個微信號的資料,例如:
<a?href="weixin://profile/gh_9261dce78e9f">挖段子冷笑話</a>其中 gh_9261dce78e9f 是微信號