判断一个网站是否是移动网站

判断一个网站是否是移动网站有很多种方法:

//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可以参考)

https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device?page=2&tab=votes#tab-top


http://yijile.com/log/239.html   //更多选择

https://blog.csdn.net/u012767761/article/details/71097888


https://m.lenovo.com.cn/   //移动site

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容