<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>判断是否为移动端运行环境</title>
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<script>
// 判断是否为移动端运行环境
var mob = '';
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
mob = 'true';
}
catch(e){}
}
}else{
mob = 'false';
};
/*使用*/
if(mob=='true') {
$('.courseOpt_list').height(48);
$('.ctrlBtn').css('bottom','-28px')
.find('i')
.removeClass('fa-angle-up')
.addClass('fa-angle-down')
.end()
.find('span')
.text('更多');
} else {
$('.courseOpt_list').height(68);
$('.ctrlBtn').css('bottom','-28px')
.find('i')
.removeClass('fa-angle-up')
.addClass('fa-angle-down')
.end()
.find('span')
.text('更多');
};
/*获取链接参数*/
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
};
//获取页面视口宽高
function getViewRect() {
var pageWidth = window.innerWidth
,pageHeight = window.innerHeight;
if ( typeof pageWidth != 'number' ) {
if ( document.compatMode == 'CSS1Compat') {
pageWidth = document.documentElement.clientWidth;
pageHeight = document.documentElement.clientHeight;
} else {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
}
}
return {
width: pageWidth,
height: pageHeight
};
};
/*判断横竖屏*/
function hengshuping(){
if(window.orientation==180||window.orientation==0){
var h = getViewRect().height;
$('html').css('minHeight',h + 'px');
}
if(window.orientation==90||window.orientation==-90){
var h = getViewRect().height;
$('html').css('minHeight',h + 'px');
}
};
if(mob == 'true') {
$(window).on('orientationchange',function() {
setTimeout(function() {
hengshuping();
},600);
});
};
var browser = {
versions: function() {
var u = navigator.userAgent, app = navigator.appVersion;
return {//移动终端浏览器版本信息
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
$('.wholePage').show();
}else if(browser.versions.ios || browser.versions.iPhone || browser.versions.iPad){
//$('#downMsg').show();
location.href = 'https://itunes.apple.com/cn/app/id1149168395';
}else{
//$('#downMsg').show();
location.href = "http://www1.zhiya100.com:8000/subject/app/zhiya100.apk";
}
</script>
</body>
</html>
html5移动端需要用的js代码
最新推荐文章于 2024-03-28 17:14:00 发布