微信中一些常用的js方法匯總
1.網(wǎng)頁(yè)圖片集左右滑動(dòng)查看圖片,如下樣例:
js效果
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( "請(qǐng)?jiān)谖⑿胖胁榭?, null, function () {});
}
}
頁(yè)面元素:
<div class="infoPics">
<div class="picImg" ng-repeat="picture in info.infoContent.pitctures">
<img ng-src="{{picture.imgPath}}" ng-click="previewPics(picture.imgPath)">
</div>
</div>
2.微信窗口關(guān)閉事件,實(shí)例如下:
WeixinJSBridge.invoke('closeWindow',{},function(res){
//alert(res.err_msg);
});
3.分享網(wǎng)頁(yè)鏈接至朋友、朋友圈、微博
var lineLink = 'http://../..',
imgUrl = 'http://../..',
shareTitle = '頁(yè)面標(biāo)題',
descContent='內(nèi)容簡(jiǎn)介',
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.隱藏網(wǎng)頁(yè)右上角按鈕
WeixinJsBridge.call('hideOptionMenu');
5.隱藏網(wǎng)頁(yè)底部導(dǎo)航欄
WeixinJsBridge.call('hideToolbar');
6.獲取當(dāng)前網(wǎng)絡(luò)連接類型:
WeixinJsBridge.invoke('getNetworkType',{},function(e){
console.log(e.err_msg);
})
7.禁止用戶分享
WeixinJsBridge.invoke('disabledShare',{},function(e){
})
8.判斷是否在微信內(nèi)置瀏覽器中打開
// true or false
var flag = WeixinApi.openInWeixin();
以上8條就是本文給大家分享的內(nèi)容了,希望對(duì)大家的微信開發(fā)能有所幫助。
相關(guān)文章
JavaScript設(shè)計(jì)模式之代理模式詳解
這篇文章主要為大家詳細(xì)介紹了JavaScript設(shè)計(jì)模式之代理模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
JavaScript使用canvas實(shí)現(xiàn)flappy bird全流程詳解
這篇文章主要介紹了JavaScript使用canvas實(shí)現(xiàn)flappy bird流程,canvas是HTML5提供的一種新標(biāo)簽,它可以支持JavaScript在上面繪畫,控制每一個(gè)像素,它經(jīng)常被用來(lái)制作小游戲,接下來(lái)我將用它來(lái)模仿制作一款叫flappy bird的小游戲2023-03-03
JavaScript實(shí)現(xiàn)正則去除a標(biāo)簽并保留內(nèi)容的方法【測(cè)試可用】
這篇文章主要介紹了JavaScript實(shí)現(xiàn)正則去除a標(biāo)簽并保留內(nèi)容的方法,結(jié)合實(shí)例形式詳細(xì)分析了javascript針對(duì)a標(biāo)簽及span標(biāo)簽的正則匹配相關(guān)操作技巧,需要的朋友可以參考下2018-07-07
javaScript中with函數(shù)用法實(shí)例分析
這篇文章主要介紹了javaScript中with函數(shù)用法,實(shí)例分析了javascript中with的功能、定義及相關(guān)使用技巧,需要的朋友可以參考下2015-06-06
JavaScript處理中文字符串的Base64編碼與解碼的兩種方法
這篇文章主要介紹了在 JavaScript 中處理中文字符串的 Base64 編碼與解碼,解釋了 Base64 編碼與中文字符沖突的原因,分別闡述了手動(dòng)實(shí)現(xiàn)和使用TextEncoder和TextDecoder API 兩種方法,包括編碼和解碼的具體實(shí)現(xiàn)及示例,最后總結(jié)了兩種方法的適用場(chǎng)景2025-01-01
Bootstrap菜單按鈕及導(dǎo)航實(shí)例解析
這篇文章主要介紹了Bootstrap菜單按鈕及導(dǎo)航的相關(guān)資料,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-09-09

