Screen Resolution has always been a tough egg to fry. In most browsers, you can't get a screen resolution. But if you can, what do you plan to do with it? If I have a screen resolution of 1600x1200, it doesn't mean that my browser is that size. So if you create a table that is 1550 pixels wide, just because you've detected my resolution, if my browser is not maximized I'm going to have to scroll all over the place to see the whole page.
In versions 4.0 and above of IE and Netscape, you can detect a much more meaningful variable: the width/height of the browser window. However, this data is obtained from the client, not from ASP. See the following examples:
IE 4+:
<script> var w = document.body.clientWidth; if (w >= 650) { window.location.href = "bigscreen.asp"; } else { window.location.href = "smallscreen.asp"; } </script> |
NN 4:
<script> var w = window.innerWidth; if (w >= 650) { window.location.href = "bigscreen.asp"; } else { window.location.href = "smallscreen.asp"; } </script> |
Of course this leaves out the 3.0 browsers. Here is how to handle this in IE 3.0, which provides the SCREEN size (note, not the window size).
IE 3:
<% smallurl = "smallscreen.asp" bigurl = "bigscreen.asp" a = Request.ServerVariables("HTTP_UA_PIXELS") url = smallurl if instr(a,"x") > 0 then a = split(a,"x") if clng(a(0)) >= 650 then url = bigurl end if end if Response.Redirect(url) %> |
And NN 3.0 has to be different... in that case, to get the screen resolution (again, not the more meaningful browser window size), you need to hook up Java.
NN 3:
<script> var Sizer = java.awt.Toolkit.getDefaultToolkit() var ScrSize = Sizer.getScreenSize(); var ScrW = ScrSize.width; if (ScrW >= 650) { window.location.href = "bigscreen.asp"; } else { window.location.href = "smallscreen.asp"; } </script> |
So, the ASP solution (which, admittedly, only takes into account the two major browsers; Opera and others will need special considerations):
<% bigurl = "bigscreen.asp" smallurl = "smallscreen.asp" A = LCase(Request.ServerVariables("HTTP_USER_AGENT")) if instr(A, "msie 6") > 0 _ or instr(A, "msie 5") > 0 _ or instr(A, "msie 4") > 0 then %> <script> var w = document.body.clientWidth; if (w >= 650) { window.location.href = "<%=bigurl%>"; } else { window.location.href = "<%=smallurl%>"; } </script> <% elseif instr(A, "msie 3") > 0 then a = Request.ServerVariables("HTTP_UA_PIXELS") url = smallurl if instr(a,"x") > 0 then a = split(a,"x") if clng(a(0)) >= 650 then url = bigurl end if end if response.redirect(url) elseif instr(A, "zilla/4") > 0 Then %> <script> var w = document.body.clientWidth; if (w >= 650) { window.location.href = "<%=bigurl%>"; } else { window.location.href = "<%=smallurl%>"; } </script> <% elseif instr(A, "zilla/3") > 0 then %> <script> var Sizer = java.awt.Toolkit.getDefaultToolkit(); var ScrSize = Sizer.getScreenSize(); var ScrW = ScrSize.width; if (ScrW >= 650) { window.location.href = "<%=bigurl%>"; } else { window.location.href = "<%=smallurl%>"; } </script> <% else respose.redirect(smallurl) end if %> |
This is a lot of manual work.
BrowserHawk will do this for you automatically, taking all browsers into account.