Home > Web Front-end > JS Tutorial > Summary of some commonly used js methods in WeChat_javascript skills

Summary of some commonly used js methods in WeChat_javascript skills

WBOY
Release: 2016-05-16 16:10:12
Original
2024 people have browsed it

1. Swipe left and right in the web page picture collection to view the pictures , as shown in the following example:

js effect

Copy code 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') {
//WeChat photo album view
WeixinJSBridge.invoke('imagePreview', {
                 'current':currentUrl, //Current address
                 'urls':pictures //Group
            });
         } else {
alert("Please check in WeChat", null, function () {});
}
}

Page elements:

Copy code The code is as follows:


              

                                                                                                                                                                                                                                               
                                                         


2. WeChat window closing event , the example is as follows:

Copy code The code is as follows:

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

3. Share web links to friends, Moments, and Weibo

Copy code The code is as follows:

var lineLink = 'http://../..',
​imgUrl = 'http://../..',
​shareTitle = 'Page title',
​descContent='Content introduction',
 appid = '';
//Determine whether WeChat js is supported
if(typeof WeixinJsBridge == 'undefined'){
​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 friends
WeixinJsBridgeReady.on('menu:share:timeline',wx_shareTimeline);//Share to Moments
WeixinJsBridgeReady.on('menu:share:weibo',wx_shareWeibo);//Share friends
}
function wx_shareFriend (){
WeixinJsBridge.invoke('sendAppMessage',{
"appid":appid,
"img_url":imgurl,
"img_width":'640',
"img_height":'500',
"link":lineLink,
"desc":descContent,
"title":shareTitle
  },function(res){
   console.log(res.err_msg);
  }
});
}
function wx_shareTimeline (){
WeixinJsBridge.invoke('sendTimeline',{
"appid":appid,
"img_url":imgurl,
"img_width":'640',
"img_height":'500',
"link":lineLink,
"desc":descContent,
"title":shareTitle
  },function(res){
   console.log(res.err_msg);
  }
})
} 
function wx_shareWeibo (){
WeixinJsBridge.invoke('sendWeibo',{
"appid":appid,
"img_url":imgurl,
"img_width":'640',
"img_height":'500',
"link":lineLink,
"desc":descContent,
"title":shareTitle
  },function(res){
   console.log(res.err_msg);
  }
})
}

4. Hide the button in the upper right corner of the web page

Copy code The code is as follows:

WeixinJsBridge.call('hideOptionMenu');

5. Hide the navigation bar at the bottom of the web page

Copy code The code is as follows:

WeixinJsBridge.call('hideToolbar');

6. Get the current network connection type:

Copy code The code is as follows:

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

7. Users are prohibited from sharing

Copy code The code is as follows:

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

8. Determine whether to open in WeChat built-in browser

Copy code The code is as follows:

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

The above 8 items are what this article will share with you. I hope it will be helpful to everyone’s WeChat development.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template