Solved

how to obtain pixel height browser is using?

Posted on 1998-09-30
4
375 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC 2 40
show form submit button based on jquery sum 5 45
How do I pull the base url for use in html links 7 31
Connection to multiple databases 13 25
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to dynamically set the form action using jQuery.
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…

829 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