WeChat_javascript スキルでよく使用されるいくつかの js メソッドの概要

WBOY
リリース: 2016-05-16 16:10:12
オリジナル
1957 人が閲覧しました

1. 次の例に示すように、Web ページの画像コレクションを左右にスワイプして を表示します。

js エフェクト

コードをコピーします コードは次のとおりです:
var photos = [];
angular.forEach(画像,関数(k,i){
photos[i] = k.imgPath;
});
$scope.previewPics = function(currentUrl){
If (typeof window.WeixinJSBridge != '未定義') {
//WeChat フォト アルバム ビュー
WeixinJSBridge.invoke('imagePreview', {
'current':currentUrl, //現在のアドレス
'urls':pictures //グループ
});
} else {
alert("WeChat で確認してください", null, function () {});
}
}

ページ要素:

コードをコピーします コードは次のとおりです:


< img ng-src = "{{picture.imgpath}}" ng-click = "previewpics(picture.imgpath)">



2. WeChat ウィンドウ終了イベント 、例は次のとおりです:

コードをコピーします コードは次のとおりです:
WeixinJSBridge.invoke('closeWindow',{},function(res){
//alert(res.err_msg);
});

3. ウェブリンクを友達、モーメント、Weibo に共有します

コードをコピー コードは次のとおりです:

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.

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!