# Detect Browser Dimension

**URL:** <https://www.ruby-forum.com/t/detect-browser-dimension/53611>\
**Category:** Ruby\
**Created:** [December 15, 2005, 6:00pm UTC](https://www.ruby-forum.com/t/detect-browser-dimension/53611 "2005-12-15T18:00:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 15, 2005, 6:00pm UTC](https://www.ruby-forum.com/t/detect-browser-dimension/53611/1 "2005-12-15T18:00:46Z")

</div>

Dear all,

I’ve just been turned on to Ruby and am trying to code a first Ruby  
CGI. I’ve already hit a brick wall.

I’m looking to see if there is a method similar to PHP’s screen.width()  
and screen.height() so I can dynamically send different sized pictures  
depending on the agent’s screen resolution.

-Christopher

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 15, 2005, 11:55pm UTC](https://www.ruby-forum.com/t/detect-browser-dimension/53611/2 "2005-12-15T23:55:33Z")

</div>

CGI is a code that executes on the server. the server does not know  
anything about the client that submits a request unless the client  
tells it about itself. there is no way to find out the screen size of  
the client’s browser unless the client side code submits a request to  
the CGI containing the dimentions. the client even can have no browser  
at all as far as the CGI script is concerned.

konstantin

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 3:38am UTC](https://www.ruby-forum.com/t/detect-browser-dimension/53611/3 "2005-12-16T03:38:57Z")

</div>

removed\_email\_address@domain.invalid wrote:

> 

One way to do this would be to use Javascript’s screen.width and  
screen.height to set some hidden input values and then read those with  
the CGI script.

-Justin

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 4:30am UTC](https://www.ruby-forum.com/t/detect-browser-dimension/53611/4 "2005-12-16T04:30:10Z")

</div>

Justin C. wrote:

> > -Christopher
> 
> One way to do this would be to use Javascript’s screen.width and  
> screen.height to set some hidden input values and then read those with  
> the CGI script.
> 
> -Justin
> 
> .

A more modern approach would be to use an AJAX request to send the  
values to the server side. You could do this onload(), and then again  
onresize() (Supported by all but Opera.) Of course, if you’re using  
Javascript you could make most adjustments on the page and avoid the  
round trip (Unless the issue _requires_ a server side adjustment, like  
building a graphic on the fly or something.)
