Last active
May 29, 2017 02:14
-
-
Save hzlzh/9803bf11ff5f182733f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
function getWxShareData() { | |
var img = 'http://xxx.xxx.com/xxx.png'; | |
var title = "分享标题"; | |
var desc = '分享详细介绍文字'; | |
var url = window.location.href.replace(/([&|\?]{1})ticket=[\w\-]+(&?)/, '$1').replace(/\?$/, ''); | |
// 这个页面hardcode写死了,就不用这样判断了 | |
// if(!img){ | |
// var imgs = document.getElementsByTagName('IMG'); | |
// if(imgs.length){ | |
// img = imgs[0].src; | |
// } | |
// } | |
return { | |
'img_url' : img, | |
'title' : title, | |
'link' : url, | |
'desc' : desc | |
}; | |
} | |
var bindit = function() { | |
// 发送给好友; | |
WeixinJSBridge.on('menu:share:appmessage', function(){ | |
WeixinJSBridge.invoke('sendAppMessage', getWxShareData(), function(r){}); | |
}); | |
// 分享到朋友圈; | |
WeixinJSBridge.on('menu:share:timeline', function(){ | |
WeixinJSBridge.invoke('shareTimeline',getWxShareData(), function(r){}); | |
}); | |
// 分享到微博; | |
WeixinJSBridge.on('menu:share:weibo', function(){ | |
var data = getWxShareData(); | |
data = { | |
url : data.link, | |
content : '【' + data.title + '】' + ' ' + data.desc + ' ' + data.link, | |
img_url : data.img_url | |
}; | |
WeixinJSBridge.invoke('shareWeibo', data, function(r){}); | |
}); | |
// 分享到Facebook | |
WeixinJSBridge.on('menu:share:facebook',getWxShareData(), function(r){}); | |
}; | |
document.addEventListener('WeixinJSBridgeReady', bindit, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment