Results 1 to 3 of 3

Thread: JavaScript Div Resize - Not Working in IE

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default JavaScript Div Resize - Not Working in IE

    For some reason, the following script is not working in IE8. You can view the context at http://www.alexjewell.com/clients/num12/index.php. Click on the Blog page and you'll notice how, since there's not enough content, everything ends before reaching the end of the viewport. The script does what it's supposed to in other browsers (Firefox and Chrome, specifically), and the content is stretched to at least the bottom of the viewport if the content doesn't already flow that far.

    What isn't working in IE?

    Code:
    function rockBody(){
    	var buddyH = document.getElementById('content');
    	var buddy = buddyH.offsetHeight+200;
    	var torso = window.innerHeight;
    	if(buddy <= torso){
    		buddyH.style.height = torso-325+"px";}
    }
    
    window.onload=rockBody;
    Thanks for any help.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    The innerHeight property doesn't work in Internet Explorer at all.

    http://code.google.com/p/doctype/wik...HeightProperty

    Getting the height of a window has always been a problem, but a simple way around it might be to use percentages? For example, if you set:
    Code:
    buddyH.style.height = "80%";
    Wouldn't hurt to give it a shot.
    - Mike

  3. #3
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    I ended up using some simple browser detection. I found out that IE supports offsetHeight, so here is what I came up with:

    Code:
    function rockBody(){
    	var buddyH = document.getElementById('content');
    	var buddy = buddyH.offsetHeight+200;
    	if (navigator.userAgent.indexOf('MSIE') !=-1){
    		document.getElementsByTagName('html')[0].style.height="100%";
    		document.getElementsByTagName('body')[0].style.height="100%";
    		var torso = document.getElementsByTagName('body')[0].offsetHeight;
    		var buddy = buddy+50;
    	}
    	else{
    		var torso = window.innerHeight;
    	}
    	if(buddy <= torso){
    		buddyH.style.height = torso-325+"px";}
    }
    
    window.onload=rockBody;
    Seems to work. Thanks!
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •