1. Definable information
1. The LOGO displayed during sharing;
2. Share the width of the LOGO;
3. Share the height of the LOGO;
4. Share the displayed title (the default call to the web page title);
5. Share the description displayed (the default call to the web page title);
6. Share the link (default is the URL of the current page).
7. Share the APPID of WeChat (usually empty).
2. How to use
1. Introduce WeChat sharing component js:
The code copy is as follows:
/*********************************************
* Author:Mr.Think
* Description: Share the general code on WeChat
*Usage method: _WXShare('Share displayed LOGO','LOGO width','LOGO height','share title','share description','share link','WeChat APPID (usually not required to fill in)');
******************************************/
function _WXShare(img,width,height,title,desc,url,appid){
//Initialization parameters
img=img||'http://a.zhixun.in/plug/img/ico-share.png';
width=width||100;
height=height||100;
title=title||document.title;
desc=desc||document.title;
url=url||document.location.href;
appid=appid||'';
// Built-in method for WeChat
function _ShareFriend() {
WeixinJSBridge.invoke('sendAppMessage',{
'appid': appid,
'img_url': img,
'img_width': width,
'img_height': height,
'link': url,
'desc': desc,
'title': title
}, function(res){
_report('send_msg', res.err_msg);
})
}
function _ShareTL() {
WeixinJSBridge.invoke('shareTimeline',{
'img_url': img,
'img_width': width,
'img_height': height,
'link': url,
'desc': desc,
'title': title
}, function(res) {
_report('timeline', res.err_msg);
});
}
function _ShareWB() {
WeixinJSBridge.invoke('shareWeibo',{
'content': desc,
'url': url,
}, function(res) {
_report('weibo', res.err_msg);
});
}
// WeixinJSBridgeReady event will be triggered when the WeChat built-in browser is initialized.
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
// Send it to friends
WeixinJSBridge.on('menu:share:appmessage', function(argv){
_ShareFriend();
});
// Share to friends
WeixinJSBridge.on('menu:share:timeline', function(argv){
_ShareTL();
});
// Share on Weibo
WeixinJSBridge.on('menu:share:weibo', function(argv){
_ShareWB();
});
}, false);
}