Solved

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

Posted on 2006-11-23
3
162 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

724 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