?
Solved

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

Posted on 2006-11-23
3
Medium Priority
?
167 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
2 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

840 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