[js中iframe改变高度和宽度]js中iframe改变高度的实例代码

时间:2021-08-22  来源:浏览器  阅读:



    
    






<script>
//  contentWindow所有浏览器支持,contentDocument IE不支持;  window.parant当前页面的父页面,window.top当前页面的最外层页面
//  iframe防钓鱼:if(window!=window.top){window.top.location.href=window.location.href} 如果最顶层页面不是当前页面,就把最顶层网址指向当前页面网址
    window.onload=function(){
        var oIframe=document.getElementById("iframePage");
        var aBtn=document.getElementsByTagName("input");
        changeHeight();
        function changeHeight(){
            setTimeout(function(){  //必须加一个延迟,不然高度改变会和页面加载冲突,事先不了高度变化
                oIframe.height=oIframe.contentWindow.document.body.offsetHeight;
            },100);
        }
        aBtn[0].onclick=function(){
            oIframe.src="1.html";
            changeHeight();
        };
        aBtn[1].onclick=function(){
            oIframe.src="2.html";
            changeHeight();
        };
    };
</script>

[js中iframe改变高度和宽度]js中iframe改变高度的实例代码

http://m.bbyears.com/bangongshuma/137476.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新