Link to home
Start Free TrialLog in
Avatar of bloodtrain
bloodtrainFlag for Canada

asked on

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
Avatar of dorward
dorward

<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>
Use self.innerWidth property to determine a window height and self.innerHeight property to determine a window height. Both supported by IE and Netscape.
Avatar of bloodtrain

ASKER

I apologize - I thought I was in the ASP forum.  I would like to detect the browser's window size using ASP (vbscript).
ASKER CERTIFIED SOLUTION
Avatar of dorward
dorward

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
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

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 https://www.experts-exchange.com/questions/20552559/Read-write-and-modify-a-text-file.html to find how to pass parameters to the server using <image> tag.