亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home WeChat Applet WeChat Development Summary of js methods commonly used in WeChat development

Summary of js methods commonly used in WeChat development

Mar 15, 2017 pm 05:26 PM

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(&#39;closeWindow&#39;,{},function(res){
       //alert(res.err_msg);
 });

3. Share the web link to friends, Moments, and Weibo

The code is as follows:

var lineLink = &#39;http://../..&#39;,
  imgUrl = &#39;http://../..&#39;,
  shareTitle = &#39;頁面標(biāo)題&#39;,
  descContent=&#39;內(nèi)容簡介&#39;,
  appid = &#39;&#39;;
//判斷是否支持微信js
 if(typeof WeixinJsBridge == &#39;undefined&#39;){
  if(document.addEventListener){
    document.addEventListener(&#39;WeixinJsBridgeReady&#39;,onBridgeReady,false);
  }else if(document.attachEvent){
    document.attachEvent(&#39;WeixinJsBridgeReady&#39;,onBridgeReady);
    document.attachEvent(&#39;onWeixinJsBridgeReady&#39;,onBridgeReady);
  }
 }else{
  onBridgeReady();
 }
function onBridgeReady (){
  WeixinJsBridgeReady.on(&#39;menu:share:appmessage&#39;,wx_shareFriend);//分享朋友
  WeixinJsBridgeReady.on(&#39;menu:share:timeline&#39;,wx_shareTimeline);//分享到朋友圈
  WeixinJsBridgeReady.on(&#39;menu:share:weibo&#39;,wx_shareWeibo);//分享朋友
}
function wx_shareFriend (){
  WeixinJsBridge.invoke(&#39;sendAppMessage&#39;,{
    "appid":appid,
    "img_url":imgurl,
    "img_width":&#39;640&#39;,
    "img_height":&#39;500&#39;,
    "link":lineLink,
    "desc":descContent,
    "title":shareTitle
    },function(res){
      console.log(res.err_msg);
    }
  });
}
function wx_shareTimeline (){
  WeixinJsBridge.invoke(&#39;sendTimeline&#39;,{
    "appid":appid,
    "img_url":imgurl,
    "img_width":&#39;640&#39;,
    "img_height":&#39;500&#39;,
    "link":lineLink,
    "desc":descContent,
    "title":shareTitle
    },function(res){
      console.log(res.err_msg);
    }
  })
}  
function wx_shareWeibo (){
  WeixinJsBridge.invoke(&#39;sendWeibo&#39;,{
    "appid":appid,
    "img_url":imgurl,
    "img_width":&#39;640&#39;,
    "img_height":&#39;500&#39;,
    "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(&#39;hideOptionMenu&#39;); 

5. Hide the bottom of the web page NavigationBar

The code is as follows:

 WeixinJsBridge.call(&#39;hideToolbar&#39;);

6. Get the current network connection type:

The code is as follows:

 WeixinJsBridge.invoke(&#39;getNetworkType&#39;,{},function(e){
    console.log(e.err_msg);
 })

7. Prohibit users from sharing

The code is as follows:

  WeixinJsBridge.invoke(&#39;disabledShare&#39;,{},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!

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72