猿问

iframe自适应高度 如何兼容360和火狐浏览器

<script type="text/javascript"> 

function reinitIframe(v_val) {

var iframe = document.getElementById(v_val);

try {

var bHeight = iframe.contentWindow.document.body.scrollHeight;

var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;

var height = Math.min(bHeight, dHeight);

iframe.height = height;

catch (ex){}

}window.setInterval("reinitIframe('autoframe')", 200); 


</script>


我有三个问题:

1.为什么要用try {...}catch (ex){}  这个有什么作用呢?

2.为什么window.setInterval("reinitIframe('autoframe')", 200); 改成reinitIframe('autoframe') 就没效果?

3.如何兼容360和火狐浏览器?

请各位老师指导,谢谢~

Sunshine518
浏览 3536回答 1
1回答

说说/shuai

1.try catch问题 建议学习 java 异常处理,一两句不太好说清 其实简单总结 就是一种提供给程序员处理运行时错误(异常)的手段(机制)。2.请先对setInterval方法进行全面了解!包括参数。3.浏览器的兼容性问题 建议简单先了解 主流浏览器的内核有哪些!,各浏览器内核的特点!再考虑浏览器的兼容性。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答