function getWindowHeight(){ return document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight; } function setTopMargin(){ var tempHeight = getWindowHeight(); tempHeight = (tempHeight > 600) ? Math.floor((tempHeight - 600) / 2) : 0; tempElement = document.getElementById('topMargin'); tempElement.style ? tempElement.style.margin = tempHeight + "px" : tempElement.padding = tempHeight; }