我们通常想要输入同样的域名,从PC端打开是PC端的页面,而用移动端打开则是移动端的页面。需要在PC端的index.html里面配置JS控制识别。如果是移动设备则自动识别跳转到移动端的域名链接,打开的是移动端的index.html页面:
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.w3.org/1999/xhtml">
<head>
<script>
function autoLoad() {
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp"; //移动设备
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; //手机浏览器
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; //uc手机浏览器
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; //windows 移动平台
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
window.location.href = 'http://m.abc.com/'; //移动端域名
}
}
</script>
</head>
<body>
</body>
</html>