首先我们需要生成一个针对自己APP的userAgent,微信对外的userAgent是micromessenger。
以下是项目中用到过的javascript的环境判断代码demo,供大家参考学习:
//微信
function is_weixin(){
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
return true;
} else {
return false;
}
}
//烽火Exmobi
function isExmobi(){
var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/txf_app/i) == 'txf_app'){
return true;
}
else{
return false;
}
}
//原生APP,其中txf_app为自定义APP标识符
function istxfapp(){
var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/txf_app/i) == 'txf_app'){
return true;
}
else{
return false;
}
}
//在以上的基础上再给个jquery判断语句
if(isExmobi()){
$(".isexmobi").removeClass("ishide");
}
else{
$(".noexmobi").removeClass("ishide");
}
}