Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2119
  • Last Modified:

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
0
bloodtrain
Asked:
bloodtrain
  • 2
  • 2
  • 2
  • +1
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now