标签:
在这里给大家介绍一款的jQuery插件,它的目的是方便大家在使用微信分享页面时调用。如有不当之处,请大家不吝赐教.
; (function ($) { $.fn.extend({ "weixinShare": function (options) { var firstImg = $("img:first"); var firstLink = window.location.href; var firstTitle = $("title").html(); options = $.extend({ img_width: firstImg.height() || "200",//宽 img_height: firstImg.width() || "200",//高 imgUrl: firstLink, lineLink: firstLink, shareTitle: firstTitle, descContent: firstTitle, appid: "aaaaaaaaaaaaaaaaaa", shareFriend: true, shareTimeline: true, shareWeibo: true, success: function () { return true; }, err: function () { return false; } }, options); var datas = { "appid": options.appid, "img_url": options.imgUrl, "img_width": options.img_width, "img_height": options.img_height, "link": options.lineLink, "desc": options.descContent, "title": options.shareTitle }; document.addEventListener(‘WeixinJSBridgeReady‘, function onBridgeReady() { // 发送给好友 WeixinJSBridge.on(‘menu:share:appmessage‘, function (argv) { if (options.shareFriend) shareOptions(‘appmessage‘); }); // 分享到朋友圈 WeixinJSBridge.on(‘menu:share:timeline‘, function (argv) { if (options.shareTimeline) shareOptions(‘timeline‘); }); //绑定‘分享到微博’按钮 WeixinJSBridge.on(‘menu:share:weibo‘, function (argv) { if (options.shareWeibo) shareOptions(‘weibo‘); }); }, false); function shareOptions(shareType) { var inVokeType; switch (shareType) { case "appmessage": inVokeType = ‘sendAppMessage‘; break; case "timeline": inVokeType = ‘shareTimeline‘; break; case "weibo": inVokeType = ‘shareWeibo‘; break; } share(inVokeType); } function share(inVokeType) { WeixinJSBridge.invoke(inVokeType, datas, function (res) { executeFun(res); }) } function executeFun(res) { if (res.err_msg.indexOf(‘confirm‘) > -1 || res.err_msg.indexOf(‘ok‘) > -1) options.success.apply(); else options.err.apply(); } } }); })(jQuery);
标签:
原文地址:http://www.cnblogs.com/ManBlog/p/4188540.html