function mobile_device_detect(url) { var thisos = navigator.platform; var os = new array("iphone", "ipod", "ipad", "android", "nokia", "symbianos", "symbian", "windows phone", "phone", "linux armv71", "maui", "untrusted/1.0", "windows ce", "blackberry", "iemobile"); for (var i = 0; i < os.length; i++) { if (thisos.match(os[i])) { window.location = url; } } //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认 if (navigator.platform.indexof('ipad') != -1) { window.location = url; } //做这一部分是因为android手机的内核也是linux //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appversion信息做判断 var check = navigator.appversion; if (check.match(/linux/i)) { //x11是uc浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件 if (check.match(/mobile/i) || check.match(/x11/i)) { window.location = url; } } //类in_array函数 array.prototype.in_array = function (e) { for (i = 0; i < this.length; i++) { if (this[i] == e) return true; } return false; } } var link = window.location.pathname + window.location.search; link = "/mobile" + link.replace('<', '').replace('>', ''); //console.log(link); mobile_device_detect(link);