|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
许多站长在写代码时候,在电脑版首页会加上一段判断移动端设备的代码,在网上找了好多个,但是效果都不理想,在2345上查看页面时发现如下代码,大家可以选择下载:
1、2345首页的代码,这个未测试。<script>
//移动设备
(function(){if(location.search==='?refer=dontgoout'){return}var ua=navigator.userAgent,mobileAgents=['Windows CE','iPod','Symbian','iPhone','BlackBerry','Android','Windows Phone','webOS','UCWEB','iPh',"dream","CUPCAKE","blackberry9500","blackberry9530","blackberry9520","blackberry9550","blackberry9800","incognito","webmate","s8000","bada","Meizu M8","LG-TU915 Obigo","LGE VX","Nokia5800","IEMobile"];for(var i=0;i<mobileAgents.length;i++){if(ua.indexOf(mobileAgents)!==-1){location.href='http://m.2345.com/';return}}}());
</script>
2、小编亲测正在用的:
附送判断XP系统的代码:
- <!-- tip_stopXP -->
- <script>
- document.write('<div class="tip_stopXP" id="J_tip_stopXP'+ stopXpNum +'" style="display:none;"><div class="inner"><ins class="e_ico"></ins><span id="J_stopXP_inner"></span><a style="position: absolute;right:21px;top:0px;color:#666;text-decoration:none;" href="#" title="关闭">不再提示</a><a href="#" title="关闭" class="e_close"></a></div></div>');
- </script>
- <!-- tip_stopXP / -->
复制代码 以下是判断电脑端和手机端的代码,小编就是用这个实现了一个页面的加密。
- function browserRedirect() {
- var sUserAgent = navigator.userAgent.toLowerCase();
- var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
- var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
- var bIsMidp = sUserAgent.match(/midp/i) == "midp";
- var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
- var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
- var bIsAndroid = sUserAgent.match(/android/i) == "android";
- var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
- var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
- if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
- window.location.href="http://www.xinmitong.cn/";
- }
- }
- browserRedirect();
复制代码
这下好了,通过几行短短的代码,可以解决很大的问题了。
|
|