Detect browser's window size

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!

Tony
LVL 2
bloodtrainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dorwardCommented:
<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
</script>
0
msa2003Commented:
Use self.innerWidth property to determine a window height and self.innerHeight property to determine a window height. Both supported by IE and Netscape.
0
bloodtrainAuthor Commented:
I apologize - I thought I was in the ASP forum.  I would like to detect the browser's window size using ASP (vbscript).
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

dorwardCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bloodtrainAuthor Commented:
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...
0
groundwarCommented:
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.

Jesse

0
msa2003Commented:
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();
</SCRIPT>

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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.