I\'m trying to get the height of a page (which might be loaded in an iframe) that has absolutely positioned elements that extend below the normal bottom of the page. Here are th
Here's the function I'm using. The major improvement is that it works for IE and chrome (whereas Alessandro's original works for firefox, but gives heights far too large for IE and chrome).
function getPageHeight() {
function getUpdatedHeight(element, originalMaxHeight) {
var top = element.offset().top;
if(typeof(top)!='undefined'){
var height = element.outerHeight();
return Math.max(originalMaxHeight, top+height);
} else {
return originalMaxHeight;
}
}
var maxhrel = 0;
if( ! $.browser.msie) {
maxhrel = $("html").outerHeight(); //get the page height
} else {
// in IE and chrome, the outerHeight of the html and body tags seem to be more like the window height
$('body').children(":not(script)").each(function(){ //get all body children
maxhrel=getUpdatedHeight($(this), maxhrel);
});
}
var atotoffset=0; // absolute element offset position from the top
$.each($('body *:not(script)'),function(){ //get all elements
if ($(this).css('position') == 'absolute'){ // absolute?
atotoffset=getUpdatedHeight($(this), atotoffset);
}
});
return Math.max(maxhrel, atotoffset);
}