js实现 iframe 宽高自适应
Posted quan846951943
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js实现 iframe 宽高自适应相关的知识,希望对你有一定的参考价值。
css
<style type="text/css" media="screen">
.box{
width: 80%;
height: 500px;
margin: 0 auto;
}
.left{
width: 20%;
height: 500px;
float: left;
border: 1px solid red;
}
#right{
width: 79%;
height: 500px;
border: 1px solid red;
float: left;
}
</style>
<div class="box">
<div class="left">
<a href="https://www.taobao.com/" title="" target="iframe_a">淘宝</a><br />
<a href="https://www.jd.com/" title="" target="iframe_a">京东</a>
</div>
<div id="right">
<iframe id="iframe" src="" name="iframe_a" frameborder="1" ></iframe>
</div>
</div>
js
<script type="text/javascript">
<script type="text/javascript">
var main = document.getElementById("right");
var iframe = document.getElementById("iframe");
var width = main.offsetWidth;
var height = main.offsetHeight;
iframe.style.width = width + "px";
iframe.style.height = (height - 5) + "px";
</script>
</script>
以上是关于js实现 iframe 宽高自适应的主要内容,如果未能解决你的问题,请参考以下文章