Solved

how to obtain pixel height browser is using?

Posted on 1998-09-30
4
376 Views
Last Modified: 2013-12-25
How do I get the pixel height of the current browser?  I am trying to use this number to determing where to scroll to.
Thanks.
0
Comment
Question by:scretti
  • 2
4 Comments
 
LVL 2

Expert Comment

by:chrisbolt
ID: 1855351
In both browsers, the JavaScript variables that hold the entire screen's width and height (eg Monitor resolution, 640x480, 800x600, etc) is:

screen.width
screen.height

In Netscape 4 and above, the JavaScript variables that hold various values are below:

window.innerHeight (the height of the page in pixels)
window.innerWidth (the width of the page in pixels)
window.pageXOffset (where the user has vertically scrolled the page to, compared to the top of the page, in pixels)
window.pageYOffset (where the user has horizontally scrolled the page to, compared to the left of the page, in pixels)

In IE 4 and above, the JavaScript variables that hold these values are:

document.body.clientHeight (the height of the page in pixels)
document.body.clientWidth (the width of the page in pixels)
document.body.scrollLeft (where the user has vertically scrolled the page to, compared to the top of the page, in pixels)
document.body.scrollTop (where the user has horizontally scrolled the page to, compared to the left of the page, in pixels)

You can find these values and do stuff with them in JavaScript. An example is below:

<SCRIPT LANGUAGE="JavaScript">
<!--
if (screen.width == 640 && screen.height == 480) {
  document.write("Your resolution is set small! :-)");
}
else {
  document.write("Your resolution is set to " + screen.width + " by " + screen.height);
}
//-->
</SCRIPT>

If you need any more help, just email me at chrisbolt@email.com or just add a comment to this question...
0
 

Author Comment

by:scretti
ID: 1855352
Sorry,
I don't need the screen resolution, just the pixel height of the font.  For example:
If I have output dynamically writen to a new window and need to scroll to a point at every 25 lines for output of maybe 300 lines, I need to calculate how many pixels that would be.  I have tried every approach to dynamically writing local anchor tags and they do not work in Netscape because of the <base> tag Netscape puts in.  That question has been posted and exhausted.  So I'm forced to use a "hokey" window.scroll to accomplish this same effect but need a way to control exactly where each line will start in pixels.  Hope this clarifies.
Thanks,
Shawn Cretti
0
 

Author Comment

by:scretti
ID: 1855353
Adjusted points to 100
0
 

Accepted Solution

by:
maximi earned 100 total points
ID: 1855354
There's no *good* way of adapting your html to the resolution that might be in use dynamically. There are Java Applets and JavaScripts but I hate this, I wouldn't want to screw my site with this garbage, so what I (and lots more) do is to design a web page that looks good in 640X480 and doesn't suck in 800X600. This can be done with tables, design and small fonts.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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