实现iframe 高度自适应
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>实现iframe高度自适应</title>
</head>
<body>
<h2>实现iframe的高度自适应</h2>
<iframe src="iframe1.html" width="600px" height="300px" frameborder="3" scrolling="no" id="iframe-content"></iframe>
</body>
<script src="jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$("#iframe-content").load(function(){
console.log($(this).contents());
var vHeight = $(this).contents().find("body").height()+32;
$(this).height(vHeight<300?300:vHeight);
})
})
</script>
</html>