Question

I want to detect users' screen size and pass this into a charting application (Chart Director by http://www.advsofteng.com) to control how big an image to display.

I have to use ASP, but I can only think to use JavaScript to detect screen-size and then pass this into the server-side script. Is there an easier way?

Thanks

Was it helpful?

Solution

No, the server knows nothing about the client other than basic info like IP and browser version. Screen resolution can easily be determined via javascript and passed to the server though, using ajax, or via form submission.

OTHER TIPS

Here is my simple solution:

javascript code:

document.cookie = "screen_w=" + screen.availWidth ;
document.cookie = "screen_h=" + screen.availHeight;

asp code:

screen_w = request.Cookies("screen_w")
screen_h = request.Cookies("screen_h")

No, this is not possible for desktop browsers. I suggest embedding an image that's appropriate for typical screen resolutions, then detecting the canvas size, and rewriting the image's src attribute to reflect that.

In any case, you don't want to look at the screen resolution, you want to look at the canvas size. Not everybody uses their browser with a maximised window, especially those with large screens. If you use the screen resolution, then you'll end up serving images that are way too big for some people.

You can't get the users screen size only the browser window size, and thats doable using javascript.

The best way that I have found to do this is to create a dummy asp page which simply has the following javascript code in the header:

<script type="text/javascript" language="JavaScript">

    document.cookie = "screen_w=" + screen.width;
        location.href = "second_page.asp"

</script>

Then in second_page.asp you can lookup the cookie, which was set in the first page. If you set and then request in the same page, it won't work first time.

myscreenwidth = request.Cookies("screen_w")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top