-
Notifications
You must be signed in to change notification settings - Fork 11
/
weixinShare.js
71 lines (68 loc) · 2.59 KB
/
weixinShare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/******************************************
函数功能: 获取图片分享到微信
******************************************/
(function() {
var firstImgs = document.querySelectorAll("img"),
firstImgSrc = "http://www1.pcauto.com.cn/zt/gz20140312/wapbaodian/img/ycbd.png";
for (var i = 0, len = firstImgs.length; i < len; i++) {
if (firstImgs[i].getAttribute('src').indexOf('http://count') == -1 && firstImgs[i].getAttribute('src').indexOf('http://acount') == -1 && firstImgs[i].getAttribute('src').indexOf('http://i1.3conline.com/') == -1) {
if (firstImgs[i].getAttribute('src2')) {
firstImgSrc = firstImgs[i].getAttribute('src2');
break;
} else {
firstImgSrc = firstImgs[i].getAttribute('src');
break;
}
}
}
var dataForWeixin = {
appId: "",
imgUrl: firstImgSrc,
url: window.location.href,
title: document.title,
desc: document.title,
fakeid: "",
callback: function() {}
};
var onBridgeReady = function() {
WeixinJSBridge.on('menu:share:appmessage', function(argv) {
WeixinJSBridge.invoke('sendAppMessage', {
"appid": dataForWeixin.appId,
"img_url": dataForWeixin.imgUrl,
"img_width": "120",
"img_height": "120",
"link": dataForWeixin.url,
"desc": dataForWeixin.desc,
"title": dataForWeixin.title
}, function(res) {
(dataForWeixin.callback)();
});
});
WeixinJSBridge.on('menu:share:timeline', function(argv) {
(dataForWeixin.callback)();
WeixinJSBridge.invoke('shareTimeline', {
"img_url": dataForWeixin.imgUrl,
"img_width": "120",
"img_height": "120",
"link": dataForWeixin.url,
"desc": dataForWeixin.desc,
"title": dataForWeixin.title
}, function(res) {});
});
WeixinJSBridge.on('menu:share:weibo', function(argv) {
WeixinJSBridge.invoke('shareWeibo', {
"content": dataForWeixin.title,
"url": dataForWeixin.url
}, function(res) {
(dataForWeixin.callback)();
});
});
};
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
}
} else {
onBridgeReady();
}
})();