/*检测浏览器方法 ------------------------------------------------*/ var pageurl = window.location.search; if(pageurl == '?m2w') { addcookie('m2wcookie', '1', 0); } //alert("设备信息:"+getcookie('m2wcookie')); if(getcookie('m2wcookie') != '1' && browserredirect()) { location.href = '/aspx/mobile/index.aspx'; } /*工具类方法 ------------------------------------------------*/ //检测是否移动设备来访 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) { return true; } else { return false; } } //写cookie function addcookie(objname, objvalue, objhours) { var str = objname + "=" + escape(objvalue); if (objhours > 0) {//为0时不设定过期时间,浏览器关闭时cookie自动消失 var date = new date(); var ms = objhours * 3600 * 1000; date.settime(date.gettime() + ms); str += "; expires=" + date.togmtstring(); } document.cookie = str; } //读cookie function getcookie(objname) {//获取指定名称的cookie的值 var arrstr = document.cookie.split("; "); for (var i = 0; i < arrstr.length; i++) { var temp = arrstr[i].split("="); if (temp[0] == objname) return unescape(temp[1]); } return ""; }