Solved

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

Posted on 2006-11-23
3
158 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

770 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