Home > Article > WeChat Applet > Summary of js methods commonly used in WeChat development
This article summarizes for you some js methods that are often used in our daily development of WeChat projects. They are all used very frequently and are very Simple method, recommended to everyone here.
1. WebpagePicturesSwipe left and right to view the pictures, as shown below:
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') { //微信图片集查看 WeixinJSBridge.invoke('imagePreview', { 'current':currentUrl, //当前地址 'urls':pictures //组 }); } else { alert( "请在微信中查看", null, function () {}); } }
Page elements:
The code is as follows:
<p class="infoPics"> <p class="picImg" ng-repeat="picture in info.infoContent.pitctures"> <img ng-src="{{picture.imgPath}}" ng-click="previewPics(picture.imgPath)"> </p> </p>
2. WeChat window closing event , The example is as follows:
The code is as follows:
WeixinJSBridge.invoke('closeWindow',{},function(res){ //alert(res.err_msg); });
3. Share the web link to friends, Moments, and Weibo
The code is as follows:
var lineLink = 'http://../..', imgUrl = 'http://../..', shareTitle = '页面标题', descContent='内容简介', appid = ''; //判断是否支持微信js 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);//分享朋友 WeixinJsBridgeReady.on('menu:share:timeline',wx_shareTimeline);//分享到朋友圈 WeixinJsBridgeReady.on('menu:share:weibo',wx_shareWeibo);//分享朋友 } 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
The code is as follows:
WeixinJsBridge.call('hideOptionMenu');
5. Hide the bottom of the web page NavigationBar
The code is as follows:
WeixinJsBridge.call('hideToolbar');
6. Get 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 it is built-in in WeChat Open
in the browser and the code is as follows:
// true or false var flag = WeixinApi.openInWeixin();
The above 8 items are the content shared with you in this article. I hope it can be helpful to everyone’s WeChat development.
The above is the detailed content of Summary of js methods commonly used in WeChat development. For more information, please follow other related articles on the PHP Chinese website!