#12003/7/28 15:27:20
我想让网页自动检测不同分辨率然后转到合适的网页,代码是
< script language=javascript>
< !--
function redirectPage(){
var url800x600=″index-86.htm″; //定义两个页面,此处假设index-ex.html和1024-ie.html同change-ie.html在同一个目录下
var url1024x768=″index.htm″;
if ((screen.width==800) && (screen.height==600)) //在此处添加screen.width、screen.height的值可以检测更多的分辨率
window.location.href= url800x600;
else if ((screen.width==1024) && (screen.height==768))
window.location.href=url1024x768;
else window.location.href=url800x600;
}
// -->
< /script>
然后再在< body…>内加入onLoad=″redirectPage()″
最后,同样地,在< body>和< /body>之间加入以下代码来显示网页的工作信息:
< script language=javascript>
< !--
var w=screen.width
var h=screen.height
document.write(″系统已检测到您的分辨率为:″);
document.write(″< font size=3 color=red>″);
document.write(w+″×″+h);
document.write(″< /font>″);
document.write(″正在进入页面转换,请稍候…″);
// -->
< /script>
测试的时候在800*600分辨率网页是可以自动转换到index-86.htm网页了,可回到1024*768分辨率下网页却不停的一遍遍的打开index.htm,也就是不停的在读代码,这是怎么回事,怎样才能让网页在1024*768分辨率就不检测了,谢谢!