我做了三个页面,分别是index.html,pc.html,phone.html,让在index.html中加入以下代码:
<script type="text/javascript">
function mobilePcRedirect() {
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";
var bIsAndroid= sUserAgent.match(/android/i) == "android";
var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
window.location.href= 'http://localhost/phone.html';
} else {
window.location= 'http://localhost/pc.html';
}
};
mobilePcRedirect();
</script>
-------------------------------------------------------------
我用的是dedecms的系统,接着就把这几个页面和样式、图片这些上传到www根目录下。
在pc打开http://localhost/index.html的时候会自动跳转到http://localhost/pc.html
在pc打开http://localhost/index.html的时候会自动跳转到http://localhost/phone.html
这看起来是正常了,万万没想到啊!这两个页面打开都是404页面。。
烦死了!
大家看出来啥原因吗
./phone.html这样写应该可以
首先去看判断有没有进去,之后再看看本地 http://localhost/phone.html 是否有内容
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)
{
alert('233'); // 这里加个断点确认这部分逻辑没问题
window.location.href= './phone.html'; // 这里试试相对目录
}
// 如果还有问题,可以去服务器检查一下,可能是设置了不允许重定向