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, //當(dāng)前地址 '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 = '頁面標(biāo)題', descContent='內(nèi)容簡介', 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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)