Detect browser's window size

Posted on 2003-03-17
Medium Priority
Last Modified: 2009-12-16
I would like to detect the browser's window size but without using browserHawk and or any other detection solution. I would like to know how to do it from scratch! :)

What I need it for is because I have a dhtml scrollable area which works on fixed positions. I don't want the positions to be fixed so I figured I could dynamically change the top & left & width values if I know the size of the browser window.

Thanks a lot!

Question by:bloodtrain
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
LVL 17

Expert Comment

ID: 8153545
<script type="text/javascript">
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
winW = (ns4)? window.innerWidth-16 : document.body.offsetWidth-20
winH = (ns4)? window.innerHeight : document.body.offsetHeight

Expert Comment

ID: 8153706
Use self.innerWidth property to determine a window height and self.innerHeight property to determine a window height. Both supported by IE and Netscape.

Author Comment

ID: 8153726
I apologize - I thought I was in the ASP forum.  I would like to detect the browser's window size using ASP (vbscript).
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 17

Accepted Solution

dorward earned 400 total points
ID: 8153802
You can't detect the browser window size with server side code. You have to use client side code, then pass it back to the server via cookies, query strings, or a POSTed form.

Author Comment

ID: 8153826
What do you think I should use, cookies or querystrings? I don't want to use forms incase the decide to refresh the page - I don't want that alert popup always coming up...

Expert Comment

ID: 8155272
Why don't you wanna use JS? What you can do is have a test page that test the client resolution using javascript and attach it to a session variable. With such in mind you could

1. Add a line to your header file (if you got one) that will redirect a client to that page, assign the client width and height variables. Clumsy, but good if you want every body to go to a main page to select a language or what not. Also good so that the client doesn't have hit back twice.

2. Add a line to your page that reloads the page and assignes the width and height to session variables. You end up having to click back twice (as a client) to exit the site, but the easiest way to do it.

If you want the code to either, just let me know.

Hope it helps.



Expert Comment

ID: 8157031
I understand your question. I have a solution for server-side scripting.

Just place the following to your website index (for example, Default.htm) in the header:

<SCRIPT LANGUAGE="JavaScript"><!--
if (self.parent.frames.length == 0) self.parent.location="http://www.dsip.net/dsip/index.asp?width="+self.innerWidth+"&height="+self.innerHeight+"r="+Math.random();

this script will redirect the user to the ASP with parameters height and width equal to the screen size.

If you do not like redirection you could do the following refer to the page http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20552559.html to find how to pass parameters to the server using <image> tag.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question