Skip to content

Instantly share code, notes, and snippets.

@chrisvogt
Created April 12, 2013 21:02
Show Gist options
  • Select an option

  • Save chrisvogt/5375110 to your computer and use it in GitHub Desktop.

Select an option

Save chrisvogt/5375110 to your computer and use it in GitHub Desktop.
Adjust scheduling iframe
function autoSizeIframeHeight(iframe, header, minHeight) {
minHeight = minHeight || 300;
function getViewportHeight() {
var h = document.documentElement.clientHeight;
return document.compatMode === "CSS1Compat" && h || document.body.clientHeight || h;
}
function getHeaderHeight() {
return parseFloat(getComputedStyle(header,'height'));
}
function getComputedStyle(el, cssprop){
if (el.currentStyle) { // IE
return el.currentStyle[cssprop];
}
else if (document.defaultView && document.defaultView.getComputedStyle) {
return document.defaultView.getComputedStyle(el, "")[cssprop];
}
else {
return el.style[cssprop];
}
}
function setIframeHeight() {
var toHeight = getViewportHeight() - getHeaderHeight();
iframe.height = Math.max(toHeight, minHeight);
body.style.overflowY = toHeight < minHeight ? 'auto' : 'hidden';
}
var body = document.body || document.getElementsByTagName('body')[0];
setIframeHeight();
if (window.addEventListener) {
window.addEventListener('resize', setIframeHeight, false);
}
else if (window.attachEvent) {
window.attachEvent('onresize', setIframeHeight);
}
}
autoSizeIframeHeight(document.getElementById('HaFrame'), document.getElementsByTagName('header')[0], 300);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment