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!