只需在header引用个js文件, 原理就是判断UA里面的标识. 加下面代码添加到js文件,在头文件引用即可
var Pc_url = ‘http://www.baidu.com‘; //PC端网址
var Phone_url = ‘http://www.sougou.com‘; //手机端网址
function IsPC(){
var userAgentInfo = navigator.userAgent;
var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
}
return flag;
}
var ispc = IsPC();
if(ispc) {
window.location.href= Pc_url;
}else{
window.location.href= Phone_url;
}