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 resizeBoxes() { var windowHeight = getWindowHeight(); var bodyHeight = document.getElementById('pageBody').offsetHeight; var headerHeight = document.getElementById('header').offsetHeight; var footerHeight = document.getElementById('footer').offsetHeight; var topOffset = document.getElementById('pageBody').offsetTop; // Si la page est plus petite que l'ecran, on l'aggrandit. if ( bodyHeight < windowHeight ) { var newBodyHeight = windowHeight - topOffset; var newContentHeight = newBodyHeight - headerHeight - footerHeight; document.getElementById('pageBody').style.height = newBodyHeight + "px" } else { var newContentHeight = bodyHeight - headerHeight - footerHeight; } // Il faut tenir compte du padding/margin sur content et sidebar a cause du box model if ( document.getElementById('sidebar').currentStyle ) { var sidebarStyles = document.getElementById('sidebar').currentStyle; var contentStyles = document.getElementById('content').currentStyle; } else if ( window.getComputedStyle(document.getElementById('sidebar'), null) ) { var sidebarStyles = window.getComputedStyle(document.getElementById('sidebar'), null); var contentStyles = window.getComputedStyle(document.getElementById('content'), null); } // Sidebar padding var sidebarPadding = parseInt(sidebarStyles.paddingBottom.substring(0, sidebarStyles.paddingBottom.indexOf('px'))) + parseInt(sidebarStyles.paddingTop.substring(0, sidebarStyles.paddingTop.indexOf('px'))); sidebarPadding = ( isNaN(sidebarPadding) ) ? 0 : sidebarPadding; // Sidebar margin var sidebarMargin = parseInt(sidebarStyles.marginBottom.substring(0, sidebarStyles.marginBottom.indexOf('px'))) + parseInt(sidebarStyles.marginTop.substring(0, sidebarStyles.marginTop.indexOf('px'))); sidebarMargin = ( isNaN(sidebarMargin) ) ? 0 : sidebarMargin; // Content padding var contentPadding = parseInt(contentStyles.paddingBottom.substring(0, contentStyles.paddingBottom.indexOf('px'))) + parseInt(contentStyles.paddingTop.substring(0, contentStyles.paddingTop.indexOf('px'))); contentPadding = ( isNaN(contentPadding) ) ? 0 : contentPadding; // Content margin var contentMargin = parseInt(contentStyles.marginBottom.substring(0, contentStyles.marginBottom.indexOf('px'))) + parseInt(contentStyles.marginTop.substring(0, contentStyles.marginTop.indexOf('px'))); contentMargin = ( isNaN(contentMargin) ) ? 0 : contentMargin; // On enleve le plus gros de chaque a la hauteur. newContentHeight -= ( contentPadding < sidebarPadding ) ? sidebarPadding : contentPadding; newContentHeight -= ( contentMargin < sidebarMargin ) ? sidebarMargin : contentMargin; document.getElementById('sidebar').style.height = newContentHeight + "px"; document.getElementById('content').style.height = newContentHeight + "px"; } function initGeneral() { resizeBoxes(); window.onresize = resizeBoxes; }