设置浏览器兼容模式
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
-webkit-appearance:none;//css初始化mac浏览器默认样式
使用H5标签与媒体查询
以下两个插件用于在IE8以及以下版本浏览器支持HTML5元素和媒体查询,如果不需要用可以移除 (建议放在<head>内)。
*H5标签<script src="[https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js(https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js)"></script>
*媒体查询<script src="[https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js(https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js)"></script>
CDN加载失败时调用本地js
<script src="[//cdn.bootcss.com/jquery/3.1.1/jquery.min.js](https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js)"></script>
若CDN加载失败则引用本地(建议放在<head>内)
<script type="text/javascript"> if(typeof jQuery == 'undefined') { document.write(unescape("%3Cscript src='js/jquery.min.js' type='text/javascript'%3E%3C/script%3E")); } </script>
百度跳转→uaredirect
实现手机访问PC链接时自动跳转到设置好的移动端网址(放于PC页面<head>内),用户体验优于设备判断跳转
function uaredirect(f){try{if(document.getElementById("bdmark")!=null){return}var b=false;if(arguments[1]){var e=window.location.host;var a=window.location.href;if(isSubdomain(arguments[1],e)==1){f=f+"/#m/"+a;b=true}else{if(isSubdomain(arguments[1],e)==2){f=f+"/#m/"+a;b=true}else{f=a;b=false}}}else{b=true}if(b){var c=window.location.hash;if(!c.match("fromapp")){if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){location.replace(f)}}}}catch(d){}}function isSubdomain(c,d){this.getdomain=function(f){var e=f.indexOf("://");if(e>0){var h=f.substr(e+3)}else{var h=f}var g=/^www\./;if(g.test(h)){h=h.substr(4)}return h};if(c==d){return 1}else{var c=this.getdomain(c);var b=this.getdomain(d);if(c==b){return 1}else{c=c.replace(".","\\.");var a=new RegExp("\\."+c+"$");if(b.match(a)){return 2}else{return 0}}}}; //参数f为手机端网址,可在后加上时间戳 uaredirect("http://m.aidaiyx.com");
资源加载完结束loading
var main = document.getElementById("main_content");//页面容器需先css设置占位隐藏 var loading = document.getElementById("loading_img");//loading图在加载结束后可选择remove方式或隐藏 document.onreadystatechange = function () { if (document.readyState == "complete") { main.style.visibility = "visible"; loading.style.display = "none"; } else { main.style.visibility = "hidden"; }; };
网友评论