首页 > 其他 > 详细

iframe 里的高度自适应

时间:2018-03-27 13:12:00      阅读:221      评论:0      收藏:0      [点我收藏+]

  由于公司里的很多东西都要用到iframe 导致我不得不各种百度

 

首先是自适应高度

 

// document.domain = "caibaojian.com";
function setIframeHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
}
}
};

window.onload = function () {
setIframeHeight(document.getElementById(‘external-frame‘));
};

其他的请到这个链接下查看:http://caibaojian.com/iframe-adjust-content-height.html

 

 

还有一个就是iframe 里的右键禁用方法:

<script>  
    document.oncontextmenu = function(){  
        return false  
    }  
</script>  

这段代码需要放在iframe内部才能生效

iframe 里的高度自适应

原文:https://www.cnblogs.com/AiMuzi/p/8656552.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!