html5移动端需要用的js代码

来源:互联网 发布:以撒的结合yum heart 编辑:程序博客网 时间:2024/05/21 12:49
<!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, //是否iPadwebApp: 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>

0 0
原创粉丝点击