Summary of common js methods in WeChat development

Source: Internet
Author: User
This article summarizes some js methods that are frequently used in our daily development projects. these methods are frequently used and very simple. we recommend them to you here. This article summarizes some js methods that are frequently used in our daily development projects. these methods are frequently used and very simple. we recommend them to you here.

1. slide the left and right sides of the webpage image set to view the image, For example:

Js effect

The code is as follows:

Var pictures = []; angular. forEach (pitctures, function (k, I) {pictures [I] = k. imgPath;}); $ scope. previewPics = function (currentUrl) {if (typeof window. weixinJSBridge! = 'Undefined') {// view WeixinJSBridge in the image set. invoke ('imagepreview', {'current': currentUrl, // current address 'urls': pictures // Group});} else {alert ("Please check in ", null, function (){});}}

Page elements:

The code is as follows:

  

2. window close event, For example:

The code is as follows:

 WeixinJSBridge.invoke('closeWindow',{},function(res){       //alert(res.err_msg); });

3. share web links to friends, friends, and Weibo

The code is as follows:

Var lineLink =' http://../ .. ', ImgUrl =' http://../ .. ', Customization title = 'Page title', descContent = 'content introduction', appid = ''; // Determine whether JavaScript if (typeof WeixinJsBridge = 'undefined') is supported ') {if (document. addEventListener) {document. addEventListener ('weixinjsbridgeready', onBridgeReady, false);} else if (document. attachEvent) {document. attachEvent ('weixinjsbridgeready', onBridgeReady); document. attachEvent ('onweixinjsbridgeready', onBridgeReady) ;}} else {onBridgeReady ();} function onBridgeReady () {WeixinJsBridgeReady. on ('menu: share: appmessage', wx_shareFriend); // share your friend WeixinJsBridgeReady. on ('menu: share: timeline ', wx_shareTimeline); // share it with WeixinJsBridgeReady. on ('menu: share: weibo ', wx_shareWeibo); // share friend} function wx_shareFriend () {WeixinJsBridge. invoke ('sendappmessage', {"appid": appid, "img_url": imgurl, "img_width": '000000', "img_height": '000000', "link ": lineLink, "desc": descContent, "title": role title}, function (res) {console. log (res. err_msg) ;}}) ;}function wx_effectimeline () {WeixinJsBridge. invoke ('sendtimeline', {"appid": appid, "img_url": imgurl, "img_width": '000000', "img_height": '000000', "link ": lineLink, "desc": descContent, "title": role title}, function (res) {console. log (res. err_msg) ;}})} function wx_incluweibo () {WeixinJsBridge. invoke ('sendweio ', {"appid": appid, "img_url": imgurl, "img_width": '000000', "img_height": '000000', "link ": lineLink, "desc": descContent, "title": role title}, function (res) {console. log (res. err_msg );}})}

4. hide the button in the upper-right corner of the webpage

The code is as follows:

 WeixinJsBridge.call('hideOptionMenu'); 

5. hide the navigation bar at the bottom of the webpage

The code is as follows:

 WeixinJsBridge.call('hideToolbar');

6. obtain the current network connection type:

The code is as follows:

 WeixinJsBridge.invoke('getNetworkType',{},function(e){    console.log(e.err_msg); })

7. prohibit users from sharing

The code is as follows:

  WeixinJsBridge.invoke('disabledShare',{},function(e){  })

8. determine whether to enable it in the built-in browser

The code is as follows:

  // true or false  var flag = WeixinApi.openInWeixin();

The above eight articles are the content shared in this article. I hope it will be helpful for your development.

The above is a summary of common js methods in development. For more information, see other related articles on php Chinese network!

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.