博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery插件之微信分享
阅读量:4561 次
发布时间:2019-06-08

本文共 2722 字,大约阅读时间需要 9 分钟。

  在这里给大家介绍一款的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);

 

转载于:https://www.cnblogs.com/ManBlog/p/4188540.html

你可能感兴趣的文章
Hive内置函数详解
查看>>
【转】MyEclipse快捷键大全
查看>>
IT职业技能图谱10--Hadoop家族技能图谱
查看>>
Java - 反射(1)
查看>>
控制台中显示执行的Sql语句
查看>>
Linux(Centos7)下搭建SVN服务器
查看>>
安卓开发的Tasks and Back Stack
查看>>
Ansi,UTF8,Unicode编码
查看>>
原子变量的性能问题
查看>>
Sybase PowerDesigner 15.0 完美版+特别文件
查看>>
快速傅立叶之二
查看>>
cetos 6.3 安装 apache+mysql+php
查看>>
js编写简单的贪吃蛇游戏
查看>>
2018/12/01 一个64位操作系统的实现 第四章 导入kernel.bin(4)
查看>>
如何在windows xp professional安装iis的解决方法
查看>>
抽象类和接口
查看>>
使用ASP.NET Atlas AutoComplete Behavior或AutoComplete Extender实现自动完成功能(下)
查看>>
golang 常见疑惑总结
查看>>
8大你不得不知的Android调试工具
查看>>
pc端元素拖拽
查看>>