最近在做一個(gè)手機(jī)站,要求點(diǎn)擊分享可以直接打開微信分享出去。而不是jiathis,share分享這種的點(diǎn)擊出來(lái)二維碼。在網(wǎng)上看了很多,都說(shuō)APP能喚起微信,手機(jī)網(wǎng)頁(yè)實(shí)現(xiàn)不了。也找了很多都不能直接喚起微信。
總結(jié)出來(lái)一個(gè)可以直接喚起微信的。適應(yīng)手機(jī)qq瀏覽器和uc瀏覽器。
下面上代碼,把這些直接放到要轉(zhuǎn)發(fā)的頁(yè)面里就可以了:
html部分:
-
<script src="mshare.js"></script>//引進(jìn)mshare.js
-
<button data-mshare="0">點(diǎn)擊彈出原生分享面板</button>
-
<button data-mshare="1">點(diǎn)擊觸發(fā)朋友圈分享</button>
-
<button data-mshare="2">點(diǎn)擊觸發(fā)發(fā)送給微信朋友</button>
js部分:
-
-
var mshare = new mShare({
-
title: 'Lorem ipsum dolor sit.',
-
-
desc: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quaerat inventore minima voluptates.',
-
img: 'http://placehold.it/150x150'
-
-
$('button').click(function () {
-
-
mshare.init(+$(this).data('mshare'));
-
-
下面是mshare.js的代碼分享,把這些代碼新建一個(gè)js文件放進(jìn)去,然后在頁(yè)面中引進(jìn)就ok了。
-
-
-
-
-
-
var UA = navigator.appVersion;
-
-
-
-
-
var uc = UA.split('UCBrowser/').length > 1 ? 1 : 0;
-
-
-
-
-
-
-
-
var qq = UA.split('MQQBrowser/').length > 1 ? 2 : 0;
-
-
-
-
-
var wx = /micromessenger/i.test(UA);
-
-
-
-
-
var qqVs = qq ? parseFloat(UA.split('MQQBrowser/')[1]) : 0;
-
var ucVs = uc ? parseFloat(UA.split('UCBrowser/')[1]) : 0;
-
-
-
-
-
-
var ua = navigator.userAgent;
-
-
if (/iphone|ipod/i.test(ua)) {
-
-
} else if (/android/i.test(ua)) {
-
-
-
-
-
-
-
-
-
-
var qqBridgeLoaded = false;
-
-
-
if ((qq && qqVs < 5.4 && os == 1) || (qq && qqVs < 5.3 && os == 1)) {
-
-
-
if (qq && qqVs < 5.4 && os == 2) {
-
-
-
if (uc && ((ucVs < 10.2 && os == 1) || (ucVs < 9.7 && os == 2))) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
var script = document.createElement('script');
-
script.src = (+qq === 1) ? '//3gimg.qq.com/html5/js/qb.js' : '//jsapi.qq.com/get?api=app.share';
-
-
-
-
-
script.onload = function () {
-
-
-
document.body.appendChild(script);
-
-
-
-
-
-
function ucShare(config) {
-
-
-
-
-
-
-
-
-
-
-
platform = config.type == 1 ? 'WechatTimeline' : 'WechatFriends';
-
-
platform = config.type == 1 ? 'kWeixinFriend' : 'kWeixin';
-
-
-
shareInfo = [config.title, config.desc, config.url, platform, '', '', ''];
-
-
-
ucweb.startRequest && ucweb.startRequest('shell.page_share', shareInfo);
-
-
-
-
ucbrowser.web_share && ucbrowser.web_share.apply(null, shareInfo);
-
-
-
-
-
-
-
-
function qqShare(config) {
-
-
-
type = type ? ((type == 1) ? 8 : 1) : '';
-
var share = function () {
-
-
-
-
'description': config.desc,
-
-
'img_title': config.title,
-
-
-
-
-
browser.app && browser.app.share(shareInfo);
-
-
qb.share && qb.share(shareInfo);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
function mShare(config) {
-
-
this.init = function (type) {
-
if (typeof type != 'undefined') this.config.type = type;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
if (typeof module === 'object' && module.exports) {
-
-
-
-
好了,這樣就可以直接喚起微信進(jìn)行分享啦