做适合不同分辨率的页 假设一个是800×600,一个是1024×768,一个是1280x960
首先我们要建立4个页面 index.html , index800x600.html ,
index1024x768.html , index1280x960.html
用javascrīpt代码加在index.html页面代码<head>和</head>中,代码如下:
<scrīpt language=Javascrīpt>
<!--
function redirectPage(){
var url800x600="index800x600.html"; //定义四个页面,此处假设index.html,index800x600.html,index1024x768.html,index1280x960.html在同一个目录下
var url1024x768="index1024x768.html";
var url1280x960="index1280x960.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 if ((screen.width==1280)&&(screen.height==960))
window.location.href= url1280x960;
else window.location.href= url800x600;
}
//-->
</scrīpt>
然后在<body ...>中加入onLoad="redirectPage()"
同样在<body>和</body>区域中加入以下代码来显示页面工作信息
<scrīpt language=Javascrīpt>
<!--
var w = screen.width
var h = screen.height
document.write("系统已检测到您的分辨率为:");
document.write("<font size=3 color=red>");
document.write(w+"X"+h);
document.write("</font>");
document.write("正在进入页面转换,请稍候…");
//-->
</scrīpt>