*新闻详情页*/>
近期在做一个手机上站,规定点一下共享能够立即开启手机微信共享出来。而并不是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')); }); </script>
下边是mshare.js的编码共享,把这种编码在建一个js文档放入去,随后在网页页面中引入就ok了。
/** * 此软件关键功效是在UC和QQ2个流行访问器 * 上边开启手机微信共享到微信朋友圈或推送朋友的作用 */ 'use strict'; var UA = navigator.appVersion; /** * 是不是是 UC 访问器 */ var uc = UA.split('UCBrowser/').length > 1 ? 1 : 0; /** * 分辨 qq 访问器 * 但是qq访问器分高矮版本号 * 2 意味着高版本号 * 1 意味着低版本号 */ 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; /** * 获得实际操作系统软件信息内容 iPhone(1) Android(2) */ var os = (function () { var ua = navigator.userAgent; if (/iphone|ipod/i.test(ua)) { return 1; } else if (/android/i.test(ua)) { return 2; } else { return 0; } }()); /** * qq访问器下边 是不是载入好啦相对的api文档 */ var qqBridgeLoaded = false; // 进一步优化版本号友谊台分辨 if ((qq && qqVs < 5.4 && os == 1) || (qq && qqVs < 5.3 && os == 1)) { qq = 0; } else { if (qq && qqVs < 5.4 && os == 2) { qq = 1; } else { if (uc && ((ucVs < 10.2 && os == 1) || (ucVs < 9.7 && os == 2))) { uc = 0; } } } /** * qq访问器下边 依据不一样版本号 载入相匹配的bridge * @method loadqqApi * @param {Function} cb 回调函数涵数 */ function loadqqApi(cb) { // qq == 0 if (!qq) { return cb && cb(); } var script = document.createElement('script'); script.src = (+qq === 1) ? '//3gimg.qq.com/html5/js/qb.js' : '//jsapi.qq.com/get?api=app.share'; /** * 必须等载入过 qq 的 bridge 脚本制作以后 * 再去原始化共享部件 */ script.onload = function () { cb && cb(); }; document.body.appendChild(script); } /** * UC访问器共享 * @method ucShare */ function ucShare(config) { // ['title', 'content', 'url', 'platform', 'disablePlatform', 'source', 'htmlID'] // 有关platform // ios: kWeixin || kWeixinFriend; // android: WechatFriends || WechatTimeline // uc 共享会立即应用截屏 var platform = ''; var shareInfo = null; // 特定了共享种类 if (config.type) { if (os == 2) { platform = config.type == 1 ? 'WechatTimeline' : 'WechatFriends'; } else if (os == 1) { platform = config.type == 1 ? 'kWeixinFriend' : 'kWeixin'; } } shareInfo = [config.title, config.desc, config.url, platform, '', '', '']; // android if (window.ucweb) { ucweb.startRequest && ucweb.startRequest('shell.page_share', shareInfo); return; } if (window.ucbrowser) { ucbrowser.web_share && ucbrowser.web_share.apply(null, shareInfo); return; } } /** * qq 访问器共享涵数 * @method qqShare */ function qqShare(config) { var type = config.type; //手机微信朋友 1, 手机微信微信朋友圈 8 type = type ? ((type == 1) ? 8 : 1) : ''; var share = function () { var shareInfo = { 'url': config.url, 'title': config.title, 'description': config.desc, 'img_url': config.img, 'img_title': config.title, 'to_app': type, 'cus_txt': '' }; if (window.browser) { browser.app && browser.app.share(shareInfo); } else if (window.qb) { qb.share && qb.share(shareInfo); } }; if (qqBridgeLoaded) { share(); } else { loadqqApi(share); } } /** * 对外开放曝露的插口涵数 * @method mShare * @param {Object} config 配备目标 */ function mShare(config) { this.config = config; this.init = function (type) { if (typeof type != 'undefined') this.config.type = type; try { if (uc) { ucShare(this.config); } else if (qq && !wx) { qqShare(this.config); } } catch (e) {} } } // 预载入 qq bridge loadqqApi(function () { qqBridgeLoaded = true; }); if (typeof module === 'object' && module.exports) { module.exports = mShare; } else { window.mShare = mShare; }
好啦,那样便可以立即勾起手机微信开展共享啦
小结
到此这篇有关HTML5东西方部访问器勾起手机微信共享作用的编码的文章内容就详细介绍到这了,大量有关html5外界勾起手机微信共享內容请检索脚本制作之家之前的文章内容或再次访问下边的有关文章内容,期待大伙儿之后多多的适用脚本制作之家!
Copyright © 2002-2020 抠图换背景_免费的抠图软件_美图抠图_手机抠图软件哪个好_p图软件哪个好用 版权所有 (网站地图) 粤ICP备10235580号