判断当前的用户是在用PC浏览器还是手机浏览器还是平板电脑浏览器
要写一段JS判断当前的用户是在用PC浏览器还是手机浏览器还是平板电脑浏览器,,怎么写好一些
要实现网页在电脑上 有个东西显示A样式
网页在平板上看,显示B样式
网页在手机上看,显示C样式
现在样式做好了!!只需要如何用JS判断是用PC浏览器还是手机浏览器还是平板电脑浏览器
[解决办法]
userAgent
[解决办法]
function getPgjs(){
var agent = navigator.userAgent.toLowerCase();
var res = agent.match(/android/);
if(res == "android")
return res;
res = agent.match(/iphone/);
if(res == "iphone")
return "ios";
res = agent.match(/ipad/);
if(res == "ipad")
return "ios";
res = agent.match(/windows/);
if(res == "windows")
return "wp";
return "pc";
}
[解决办法]