让网页适应不同的浏览器和分辨率2
作者:马志勇 来源:中国电脑教育报 添加时间:2006-5-21 9:22:26
图2
< script language=JavaScript>
< !--
function redirectPage(){
var url800x600=″index-ie.html″; //定义两个页面,此处假设index-ex.html和1024-ie.html同change-ie.html在同一个目录下
var url1024x768=″1024-ie.html″;
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>
好了,一切工作完成,试一试效果,感觉不错吧?你也可以来访笔者的主页http://www.jixie2000.yes8.com/看一下效果,但只是看效果呦,至于页面请不要见笑!呵呵……