<script type="text/javascript">
/**
* 获取客户端信息
*/
function getClientInfo() {
var userAgentInfo = navigator.userAgent;
var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
var agentinfo = null;
for (var i = 0; i < Agents.length; i++) {
if (userAgentInfo.indexOf(Agents[i]) > 0) { agentinfo = userAgentInfo; break; }
}
if (agentinfo) {
return agentinfo;
} else {
return "PC";
}
}
//调用示例
alert(getClientInfo());
</script>
1、pc端写 (如果是移动端跳走)
!function(){
function params(u, p){
var m = new RegExp("(?:&|/?)"+p+"=([^&$]+)").exec(u);
return m ? m[1] : '';
}
if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == true && params(location.search, "from") != "mobile"){
location.href = 'http://m.XXX.com';
}
}();
2、移动端写 (如果打开是pc跳走)
!function(){
if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == false){
location.href = 'http://XXX.com';
}
}();
网友评论