Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  100] [ 6]  / answers: 1 / hits: 71243  / 14 Years ago, tue, july 20, 2010, 12:00:00

Depending on which mode of IE8 i'm in (quirks or standard) i get different values for the height and width. I've tried standard javascript and jquery but both return different results.



In Quirks



$('body').width = 1239  
$('body').height = 184
document.body.clientWidth = 1231
document.body.clientHeight = 176


In standards



$('body').width = 1260  
$('body').height = 182
document.body.clientWidth = 1254
document.body.clientHeight = 176


Any ideas how to get a value unchanged by the mode of IE8.



Thanks in adv.


More From » jquery

 Answers
23

Perhaps the issue is due to the scrollbars being included in the width and height regardless of whether or not they are there. I don't have IE (on a mac) so can't verify.



However, I can tell you what does work as in my project jQuery Lightbox I have no such issue. We use the following code in it:



// Make the overlay the size of the body
var $body = $(this.ie6 ? document.body : document); // using document in ie6 causes a crash
$('#lightbox-overlay').css({
width: $body.width(),
height: $body.height()
});

// ... some code ...

// Get the window dimensions
var $window = $(window);
var wWidth = $window.width();
var wHeight = $window.height();


And the overlay displays correctly. I would trust jQuery's result of the width and height compared to that of the native result, as jQuery should naturally be taking into account any quirks with the browser.



It is important to note that the lightbox script above tends to prefer $(document) over $(document.body) for some reason - I can't remember sorry :O - so perhaps this solves the issue as well?


[#96171] Saturday, July 17, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;