在开发网站时,有时候会因客户端和服务器的分辨率不同而影响整体效果,本实例将给出解决该问题的方法。
设有3个网页:Default.aspx、Index.aspx和Main.aspx,其中Index.aspx或Main.aspx是网站的首页,Index.aspx在分辨率为1024*768的情况下可以正常浏览,main.aspx在分辨率为800*600的情况下可以正常浏览,Default.aspx的引入是作为主页的转向。
在Default.aspx网页中需要添加如下代码,对浏览器的分辨率进行检验,并进行相应的跳转。
<body>
<script language=”javascript”>
Var w=screen.width;
Var h=screen.height;
If(w==”1024”&&h==””)
{
Window.location.href=”Main.aspx”
}
Else
{
Window.location.href=”Index.aspx”
}
</script>
</body>
在index.aspx页中需要添加如下代码,如果分辨率为800*600则转向main.aspx首页中,不能进入index.aspx首页中。
<script language=”javascript”>
Var w=screen.width;
Var h=screen.height;
If(w==”800”&&h=”600”)
{
Window.location.href=”Main.aspx”
}
</script>
在main.aspx页中需要添加如下代码,如果分辨率为1024*768则转向index.aspx首页中,不能进入main.aspx首页中。
<script language=”javascript”>
Var w=screen.width;
Var h=screen.height;
If(w==”1024”&&h=”768”)
{
Window.location.href=”Index.aspx”
}
</script>