利用js自动检测pc端和移动端,js代码,需要写两个网页,一个pc,一个移动端

假设pc/index.html是pc端的网页,mobile/index.html是移动端的网页
在外部设置一个html进行判断,分别跳转;

//判断如果是pc端,自动跳到pc/index.html
//安卓手机自动跳到mobile/index.html
var userAgent = navigator.userAgent.toLowerCase();

        if(userAgent.indexOf('android') == -1 &&
        userAgent.indexOf('iphone') == -1 &&
        userAgent.indexOf('ipad') == -1)

        location.href = 'pc/index.html';
        else
        location.href = 'mobile/index.html';

版权声明:本文为z110655原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。