Created
October 3, 2012 04:18
-
-
Save snowman-repos/3824970 to your computer and use it in GitHub Desktop.
jQuery: Resize iFrame to Fit Content (Same Domain)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script> | |
<script type='text/javascript'> | |
$(function(){ | |
var iFrames = $('iframe'); | |
function iResize() { | |
for (var i = 0, j = iFrames.length; i < j; i++) { | |
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';} | |
} | |
if ($.browser.safari || $.browser.opera) { | |
iFrames.load(function(){ | |
setTimeout(iResize, 0); | |
}); | |
for (var i = 0, j = iFrames.length; i < j; i++) { | |
var iSource = iFrames[i].src; | |
iFrames[i].src = ''; | |
iFrames[i].src = iSource; | |
} | |
} else { | |
iFrames.load(function() { | |
this.style.height = this.contentWindow.document.body.offsetHeight + 'px'; | |
}); | |
} | |
}); | |
</script> | |
<iframe src="content.html" class="iframe" scrolling="no" frameborder="0"></iframe> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment