Skip to content

Instantly share code, notes, and snippets.

@why404
Last active October 28, 2015 03:38
Show Gist options
  • Save why404/cfb914b0358c1783544d to your computer and use it in GitHub Desktop.
Save why404/cfb914b0358c1783544d to your computer and use it in GitHub Desktop.
<script type="text/javascript">
// Not Required
var gSound = 'A background-music.mp3 URL';
var playsound = function()
{
var audio = new Audio();
audio.loop = true;
audio.src = gSound;
document.body.appendChild(audio);
audio.play();
};
var appId = '',
imgUrl = 'Icon URL for share',
link = 'Page URL for share',
title = 'Title for share',
desc = 'Description for share';
(function(){
var onBridgeReady = function () {
playsound();
// 发送给好友;
WeixinJSBridge.on('menu:share:appmessage', function(argv){
WeixinJSBridge.invoke('sendAppMessage',{
'img_url' : imgUrl,
'img_width' : '640',
'img_height' : '640',
'link' : link,
'desc' : desc,
'title' : title
}, function(res) {});
forward();
});
// 分享到朋友圈;
WeixinJSBridge.on('menu:share:timeline', function(argv){
WeixinJSBridge.invoke('shareTimeline',{
'img_url' : imgUrl,
'img_width' : '640',
'img_height' : '640',
'link' : link,
'desc' : desc,
'title' : '《'+title+'》'+desc
}, function(res) {
});
share();
});
};
if(document.addEventListener){
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if(document.attachEvent){
document.attachEvent('WeixinJSBridgeReady' , onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady' , onBridgeReady);
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment