首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

界别PC还是移动设备useragent的javascript代码

2012-06-27 
区分PC还是移动设备useragent的javascript代码判断useragent是来自普通pc,还是来自移动设备。普通pc打开ind

区分PC还是移动设备useragent的javascript代码
判断useragent是来自普通pc,还是来自移动设备。普通pc打开index-pc.html,移动设备打开index-m.html

var deviceAgent = navigator.userAgent.toLowerCase();var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);if(agentID){if(agentID.indexOf("iphone")>=0 || agentID.indexOf("ipod")>=0 || agentID.indexOf("ipad")>=0 || agentID.indexOf("android")>=0){window.location="index-m.html";}else{window.location="index-pc.html";}}else{window.location="index-pc.html";}

热点排行