Click to See Complete Forum and Search --> : Is there any way to find out the viewer's resolution?
goofy1989
11-05-2005, 05:29 PM
Like the title suggests, is there a way in ASP (or anything else for that mattter) to find out what resolution somebody is viewing my site at.
I ask this because the site looks great in 1280x1024, but in 1024x768, the site cuts off a little bit. If there's some way to find out their resolution, then I would be able to shrink a couple images so that everything fits right in 1024x768.
Thanks in advance!!
Giskard
11-05-2005, 08:39 PM
Since ASP runs on your server and then sends HTML to the client - there is no way for ASP to determine the client resolution.
However, JavaScript runs on the client and by using the screen.width and screen.height properties to get the client's resolution. Then you can either use JavaScript to resize the images or have JavaScript reload the page sending the width and height to the ASP as parameters (I haven't tried this and I'm not sure how pop-up blockers would react since you'd be doing a redirect in a pageload event).
The problem with this solution is that it may not work on older browsers. If this is a concern then maybe what you want to do is assume that the client has a low resolution screen and set it to a higher resolution if posible.
buntine
11-06-2005, 05:47 AM
By default, that information is not passed as a header to the server upon a page request (would be cool if it was, though).
You can, however, install the BrowserHawk component, which, I assume, performs an automated postback and gets all of the required information from the client. It's not free, but worthwhile in some cases.
Try a Google search for more information on it. I have not personally used it.
Regards.
goofy1989
11-09-2005, 09:13 PM
Thanks you two that responded. BrowserHawk looked really cool, except for the fact that it's like $400 or something. So the JavaScript way works (obviously).
But now I would like to make some ASP out of the results of that.. Something like this:
<% dim ScreenWidth
ScreenWidth=(Screen Width from the JavaScript)
%>
I've tried a few ways to do this, but I couldn't figure it out... how can I do this?
Giskard
11-09-2005, 10:44 PM
If you want the ASP to know what the JavaScript has found out then you need to do a postback to the same page. Here is a quick page that I just threw together that will do what you want. Just cut and paste the code into a file named Resolution.asp and you'll see how it works. Just remember that the JavaScript is redirecting the browser and I can't guarentee that all pop-up blockers will be ok with it.
<% @Language = "VBScript" %>
<HTML>
<HEAD>
<title id=titletext>Screen Resolution</title>
<%
' use a variable to determine if this is the first time viewing this page or not
Postback = Request("Postback")
If Postback <> "1" then
' The script is only executed if this is not a postback
' The document location is set to the current page with the Postback, Width, and Height parameters
Response.write(_
"<script language=JavaScript>" & _
"document.location='Resolution.asp?Postback=1&width='+screen.width+'&height='+screen.height" & _
"</script>")
end if
%>
</HEAD>
<body>
<% ' The width and height are now available to the ASP since this will only execute if the page
' is a postback and the parameters are present %>
width=<%=Request("width")%>
<br>
height=<%=Request("height")%>
</BODY>
</HTML>
Let me know if you have any questions on the code.