简要说明 contentWindow, contentDocument
项目上需要封装一个上传, 找了N多个上比较好的上传插件,无非两种:
一种是 swf: 但 一些浏览器不支持了
一种是iframe: 最多兼容到 IE9
-----------------------------------------------------
如果iframe的出现是一个错误的话,iframe里边在来一个iframe那是错上加错
contentWindow 兼容各个浏览器,可取得子窗口的 window 对象。
contentDocument Firefox 支持,> ie8 的ie支持。可取得子窗口的 document 对象。
在子级iframe设置 父级 iframe ,或 孙级 iframe 高度。
function showIframeH(){
var parentWin = parent.document.getElementById("test");
if(!parentWin) return false;
var sub = parentWin.contentWindow.document.getElementById("test2");
if(!sub) return false;
var thirdHeight = sub.contentWindow.document.body.offsetHeight; //第三层 body 对象
sub.height = thirdHeight; //设置第二层 iframe 的高度
var secondHeight = x.contentWindow.document.body.offsetHeight; //第二层 body 对象
x.height = secondHeight; //设置第一层 iframe 的高度
//alert(secondHeight);
//alert('body: ' + x.contentDocument.body.offsetHeight + ' div:' + thirdHeight);
}