判断一个网站是否是移动网站有很多种方法:
//solution 1
(function(Switch){
var switch_pc = window.location.hash;
if(switch_pc != "#pc"){
if(/iphone|ipod|ipad|ipad|Android|nokia|blackberry|webos|webos|webmate|bada|lg|ucweb|skyfire|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile/i.test(navigator.userAgent.toLowerCase())){
Switch.location.href='http://www2.samemart.com/index2.html';
}
}
})(window);
//solution 2
if (/Mobi/.test(navigator.userAgent)) {
// mobile!
window.location="http://www2.samemart.com/index2.html"
}
//solution 3
//判断是否为移动端 true为移动端
function isMobile() {
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;
}
}
alert("Is this page mobile page: "+isMobile());
//more solutions (话说stackoverflow有很多css/js可以参考)
http://yijile.com/log/239.html //更多选择
https://blog.csdn.net/u012767761/article/details/71097888
https://m.lenovo.com.cn/ //移动site