Skip to content

Instantly share code, notes, and snippets.

@iyank4
Created September 15, 2013 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iyank4/6573334 to your computer and use it in GitHub Desktop.
Save iyank4/6573334 to your computer and use it in GitHub Desktop.
Javascript Autoresize iframe.
<iframe id="myID" src="THE_URL" width="100%" height="20" frameborder="0"></iframe>
<script>
function setIframe() {
$("#dsct").animate({height: $("#dsct").contents().height()+"px"}, 500)
}
$("#myID").load(function() {
setIframe(); // got false height, so we need to execute again after 1 second
setTimeout(function(){ setIframe() },1000);
// all the link in the iframe will be targeted to parent window
$("#myID").contents().find('head').append('<base target="_parent" />');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment