Examples of Javascript Web-based WeChat sharing

Source: Internet
Author: User


I had previously encountered the WeChat sharing function in the project, and I sorted it out myself. The specific code is as follows:

The sharing feature is different from the sharing feature of the app, but the sharing feature is limited. You cannot display the titles, icons, and descriptions you want to display. All WeChat sharing interfaces are required.

Var title = "{info. data. intro }}";
Var desc = "{info. data. intro }}";
Var appId = "{info. data. string. appi }}";
Var timestamp = "{info. data. string. timestamp }}";
Var signature = "{info. data. string. signature }}";
Var id = "{info. data. id }}";
 
Wx. config ({
Debug: false,
AppId: appId,
Timestamp: timestamp,
NonceStr: 'wm3wzytpz0wzccnw ',
Signature: signature,
JsApiList :[
'Checkjsapi ',
'Onmenusharetimeline ',
'Onmenushareappmessage ',
'Onmenushareqq ',
'Onmenushareqzone'
]
});
 
// Trigger a click event
Wx. ready (function (){
$ ('. Sh-header-share'). trigger ("click ");
});
 
$ (". Sh-header-share"). on ("click", upload action );
Function compute action (){
 
Var link = window. location. href;
 
Var img = "{% if info. data. banner [0] is defined %} {info. data. banner [0] }{% endif % }";
 
// Share with your friends
Wx. onMenuShareTimeline ({
Title: title, // share the title
Link: link, // sharing link
ImgUrl: img, // share icon
Success: function (){
// The callback function executed after the user confirms the sharing
GetGold (id );
},
Cancel: function (){
// The callback function executed after the user cancels the sharing
Alert ("share canceled ");
}
});
 
// Share with friends
Wx. onMenuShareAppMessage ({
Title: title, // share the title
Desc: desc, // share the description
Link: link, // sharing link
ImgUrl: img, // share icon
Type: '', // share type, such as music, video, or link. If this parameter is not specified, the default value is link.
DataUrl: '', // if the type is music or video, provide a data link. The default value is null.
Success: function (){
// The callback function executed after the user confirms the sharing
GetGold (id );
},
Cancel: function (){
// The callback function executed after the user cancels the sharing
Alert ("share canceled ");
}
});
 
// Share it with QQ
Wx. onMenuShareQQ ({
Title: title, // share the title
Desc: desc, // share the description
Link: link, // sharing link
ImgUrl: img, // share icon
Success: function (){
// The callback function executed after the user confirms the sharing
},
Cancel: function (){
// The callback function executed after the user cancels the sharing
// Alert ("share canceled ");
}
});
 
// Share to QQ space
Wx. onMenuShareQZone ({
Title: title, // share the title
Desc: desc, // share the description
Link: link, // sharing link
ImgUrl: img, // share icon
Success: function (){
// The callback function executed after the user confirms the sharing
},
Cancel: function (){
// The callback function executed after the user cancels the sharing
// Alert ("share canceled ");
}
});
}
 
</Script>

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.