Js Implementation of Common WeChat sharing component example _ basic knowledge

Source: Internet
Author: User
This article mainly introduces the sharing common components used to define the sharing information for Browsing webpages in a browser. If you need them, refer I. definable Information

1. LOGO displayed during sharing;
2. Share the LOGO width;
3. Share the LOGO height;
4. Share the title displayed on the webpage (the webpage title is called by default );
5. Share the displayed description (by default, the webpage title is called );
6. Share a link (the URL of the current page by default ).
7. Share the APPID (usually empty ).

Ii. Usage

1. Introduce the sharing component js:

The Code is as follows:


/*******************************
* Author: Mr. Think
* Description: share common code.
* Usage: _ WXShare ('share the LOGO ', 'logo width', 'logo high', 'share title', 'share description', 'share link ', 'appid (not required )');
*******************************/
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
Function _ reset friend (){
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 ('effectimeline ',{
'Img _ url': img,
'Img _ width': width,
'Img _ height': height,
'Link': url,
'Desc': desc,
'Title': title
}, Function (res ){
_ Report ('timeline', res. err_msg );
});
}
Function _ revoke WB (){
WeixinJSBridge. invoke ('invalid weio ',{
'Content': desc,
'Url': url,
}, Function (res ){
_ Report ('weibo ', res. err_msg );
});
}
// When the built-in browser is initialized, The WeixinJSBridgeReady event is triggered.
Document. addEventListener ('weixinjsbridgeready', function onBridgeReady (){
// Send it to a friend
WeixinJSBridge. on ('menu: share: appmessage', function (argv ){
_ Begin friend ();
});

// Share with your friends
WeixinJSBridge. on ('menu: share: timeline ', function (argv ){
_ ShareTL ();
});

// Share on Weibo
WeixinJSBridge. on ('menu: share: Weaver ', function (argv ){
_ Required WB ();
});
}, False );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.