当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js实现QQ、微信、新浪微博分享功能

js实现QQ、微信、新浪微博分享功能

2018年10月25日  | 移动技术网IT编程  | 我要评论

使用js实现qq、微信、新浪微博分享功能。

微信分享需要手机扫描二维码,需要对url进行编码。

js代码:

 1 var sharemodel = {
 2 
 3         /**
 4          * 分享qq好友
 5          * @param  {[type]} title [分享标题]
 6          * @param  {[type]} url   [分享url链接,默认当前页面链接]
 7          * @param  {[type]} pic   [分享图片]
 8          * @return {[type]}       [description]
 9          */
10         shareqq: function (url, title, pic) {
11             var param = {
12                 url: url || window.location.href,
13                 desc: '', /*分享理由*/
14                 title : title || '', /*分享标题(可选)*/
15                 summary : '',/*分享描述(可选)*/
16                 pics : pic || '',/*分享图片(可选)*/
17                 flash : '', /*视频地址(可选)*/
18                 site: '' /*分享来源 (可选) */
19             };
20             var s = [];
21             for (var i in param) {
22                 s.push(i + '=' + encodeuricomponent(param[i] || ''));
23             }
24             var targeturl = "http://connect.qq.com/widget/shareqq/iframe_?" + s.join('&') ;
25             window.open(targeturl, 'qq', 'height=520, width=720');
26         },
27 
28         /**
29          * 微信分享
30          * @return {[type]} [description]
31          */
32         weixin: function () {
33             var url = window.location.href,
34                 encodepath = encodeuricomponent(url),
35                 targeturl = 'http://qr.liantu.com/api.php?text=' + encodepath;
36             window.open(targeturl, 'weixin', 'height=320, width=320');
37         },
38 
39         /**
40          * 分享新浪微博
41          * @param  {[type]} title [分享标题]
42          * @param  {[type]} url   [分享url链接,默认当前页面]
43          * @param  {[type]} pic   [分享图片]
44          * @return {[type]}       [description]
45          */
46         sinaweibo: function (title, url, pic) {
47             var param = {
48                 url: url || window.location.href,
49                 type: '3',
50                 count: '1', /** 是否显示分享数,1显示(可选)*/
51                 appkey: '', /** 您申请的应用appkey,显示分享来源(可选)*/
52                 title: '', /** 分享的文字内容(可选,默认为所在页面的title)*/
53                 pic: pic || '', /**分享图片的路径(可选)*/ 
54                 ralateuid:'', /**关联用户的uid,分享微博会@该用户(可选)*/
55                 rnd: new date().valueof()
56             }
57             var temp = [];
58             for( var p in param ) {
59                 temp.push(p + '=' +encodeuricomponent( param[p ] || '' ) )
60             }
61             var targeturl = 'http://service.weibo.com/share/share.php?' + temp.join('&');
62             window.open(targeturl, 'sinaweibo', 'height=430, width=400');
63         }
64     };

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网