Solved

Auto Height script not working in I.E 7 any ideas?

Posted on 2006-11-23
3
161 Views
Last Modified: 2010-04-09
Hello, I have been using the following script to stretch the height of a window to match 100% vertical window space.

In most browsers the script scales perfectly including IE 6. The body content is either stretched to match the available vertical space or if the content of the page is greater than the height of the window then it wraps accordingly.

In IE7 if the content exceeds the vertical space the footer stays where it is.

You can see a working example here: http://pubs.merrions.com (make sure you scroll down to see the problem).

Can anyone spot what is wrong with the following code? I'm useless with Javascript, this was written by someone before me and I haven't got a clue?



-----------------------------------------------------------------------------------Code starts-------
function getWindowHeight() {
     var windowHeight = 0;
     if (typeof(window.innerHeight) == 'number') {
          windowHeight = window.innerHeight;
     }
     else {
          if (document.documentElement && document.documentElement.clientHeight) {
               windowHeight = document.documentElement.clientHeight;
          }
          else {
               if (document.body && document.body.clientHeight) {
                    windowHeight = document.body.clientHeight;
               }
          }
     }
     return windowHeight;
}

function setMain() {
     if (document.getElementById) {
          var windowHeight = getWindowHeight();
          if (windowHeight > 0) {


               // how tall is the header?
               var headerHeight = document.getElementById('header').offsetHeight;


               // how tall is the content area?
               var contentElement = document.getElementById('contentHolder');
               var contentHeight  = contentElement.offsetHeight;


               //how tall is the footer?
               var footerHeight = document.getElementById('footer').offsetHeight;

               //now lets get everything to line up...
                  var totalHeight = (windowHeight - (headerHeight + footerHeight))

               contentElement.style.height = totalHeight + 'px';
          }
     }
}

window.onload = function()
{
     setMain();
}

window.onresize = function()
{
     setMain();
}
-----------------------------------------------------------------------------------Code ends---------



I would be very grateful to anyone who would shed some light on the situation.

Kindest regards

Chris
0
Comment
Question by:chrissp26
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Expert Comment

by:madutis
ID: 18129240
My 7 years of experience in HTML and Web Development suggests that you never set height of the web page to 100%.

1. There is no reason you'll want this.
2. What happens if the user have one of those monitors where you can rotate screen vertically or browsing on WebTV? Your page will look very bad.
3. You can never adjust such scripts for all (or most) browsers around, or if you could, the script becomes really complex and monstrous.

Just my 2 cents.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18400424
PAQed with points refunded (500)

Computer101
EE Admin
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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Compute age Html 2 36
w3c parsing errors 4 36
Need advice on an App idea......but who do I ask? 2 67
transfer content to new site design 7 45
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

739 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