Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
lastpass auto fill login form 5 25
Bootstap Icons 3 22
Bootstrap 3 icons 3 15
Help position a graphic properly via CSS 4 7
Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now