设置iframe自适应高度(/*兼容FF/IE9/IE8/IE7/IE6*)
2011-10-19 16:18
531 查看
js:
function iFrameHeight() {
var ifm= document.getElementById("iframepage");
var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
}
iframe:
<iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="width:100%; " onLoad="iFrameHeight()"></iframe>
下面的兼容性比较好:
/*兼容FF/IE9/IE8/IE7/IE6*/
function iframeResize(iframe) {
try {
//var iframe = document.getElementById("contentFrame"); //("contentFrame");
var idocumentElement = iframe.contentWindow.document.documentElement;
if (idocumentElement.scrollHeight > 560) {
iframe.height -= 5;
iframe.height = idocumentElement.scrollHeight;
}
else {
iframe.height = 560;
}
}
catch (e) {
window.status = 'Error: ' + e.number + '; ' + e.description;
}
}
iframe:
<iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="width:100%; " onLoad="iframeResize(this)"></iframe>
function iFrameHeight() {
var ifm= document.getElementById("iframepage");
var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
}
iframe:
<iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="width:100%; " onLoad="iFrameHeight()"></iframe>
下面的兼容性比较好:
/*兼容FF/IE9/IE8/IE7/IE6*/
function iframeResize(iframe) {
try {
//var iframe = document.getElementById("contentFrame"); //("contentFrame");
var idocumentElement = iframe.contentWindow.document.documentElement;
if (idocumentElement.scrollHeight > 560) {
iframe.height -= 5;
iframe.height = idocumentElement.scrollHeight;
}
else {
iframe.height = 560;
}
}
catch (e) {
window.status = 'Error: ' + e.number + '; ' + e.description;
}
}
iframe:
<iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="width:100%; " onLoad="iframeResize(this)"></iframe>
相关文章推荐
- 解决iFrame自适应高度(兼容IE6,IE7与FireFox)
- 设置DIV最小高度以及高度自适应(兼容IE6和火狐)
- 解决火狐iframe自适应高度,兼容IE6、7、8
- JavaScript设置IFrame高度自适应(兼容多浏览器)
- JavaScript设置IFrame高度自适应(兼容多浏览器)
- iframe自适应高度(简单经典)兼容ie6-ie9 ,firefox,opera,chrome
- JavaScript设置IFrame高度自适应(兼容多浏览器)
- 跨域访问Iframe自适应高度(兼容Firfox,IE)
- iframe自适应高度(兼容多种浏览器)
- iframe显示高度自适应 兼容多浏览器
- iframe自适应高度(兼容多种浏览器)
- Iframe跨域自适应高度(兼容IE/Firefox)终极解决方案
- iframe 高度设置、iframe 自适应高度方法总结
- js实现的非跨域的iframe高度自适应(完美兼容IE,FF,Opera)
- iframe中有ajax,设置iframe自适应高度
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- iframe自适应高度(兼容多种浏览器)
- 兼容主流浏览器的 iframe 自适应高度(很实用)