未捕获的类型错误:无法读取 Firefox 和 Chrome 中的属性“innerHTML”
Uncaught TypeError: Cannot read property 'innerHTML' in Firefox and Chrome
我在JS的站点中有文件上传代码:
function detectDone(){
done++;
var _ifrWallp = document.getElementById("ifrWallp");
var html = _ifrWallp.contentWindow.document.body.innerHTML;
if (html.indexOf('File name:') != -1) {
// Done
uploadedWall();
} else {
setTimeout('detectDone()',10);
}}
和 HTML:
<div id="addWallpp" class="addMWallp" style="float: left;" onmouseover="document.getElementById('uploadDesc').style.display = 'block'; document.getElementById('ifrWallp').contentWindow.document.getElementById('wpmain').style.backgroundColor = '#FFF7C0';" onmouseout="document.getElementById('uploadDesc').style.display = 'none'; document.getElementById('ifrWallp').contentWindow.document.getElementById('wpmain').style.backgroundColor = '#F9F9F9';">
<iframe id="ifrWallp" onload="Upload('../')" scrolling="no" frameborder="0" style="text-align:center;vertical-align:middle;border-style:none;margin:0px;width:100%;height:45px" src="sources/private/upload.php"></iframe>
和 PHP 文件中的一些代码。在IE中我没有错误,但是chrome和Firefox在行中给出了错误:
var html = _ifrWallp.contentWindow.document.body.innerHTML;
未捕获的类型错误:无法读取 null 的属性"innerHTML"
在FF中:
类型错误: _ifrWall.contentWindow.document.body 为空
我知道我必须在页面加载后加载 iframe 代码,但不幸的是我不知道如何让它与我的文件上传一起使用。请帮忙:(
请参阅此处的说明和代码示例:http://www.sitepoint.com/forums/showthread.php?405244-InnerHTML-and-Firefox
基本上contentWindow是一个IE的东西。对于 FF,您需要使用 contentDocument。
//ff
if (_ifrWallp.contentDocument){
var html=_ifrWallp.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
}
//ie
else if (_ifrWallp.contentWindow){
var html=_ifrWallp.contentWindow.document.body.innerHTML;
}
// if (html.indexOf('File name:') ... etc
相关文章:
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 不可枚举的属性出现在 for..在 Chrome 中循环
- 在Chrome中隐藏__proto__属性's控制台
- javascript:阻止表示添加的数组's属性作为元素(在Chrome中)
- Google Chrome中的计算属性名称({[a]:1})
- chrome.tabs.query:属性'currentWindow':想不到的
- 这个关键字在Safaari vs.Chrome,Firefox,IE中具有select box onchange属性
- html数据属性在firefox中使用javascript时没有按预期显示,但在chrome中显示正确
- 拖放文件时,dataTransfer.items属性在Firefox和IE中未定义,但在Chrome中未定义
- 删除属性后刷新DOM,而不象chrome那样刷新页面
- Chrome 不支持 Javascript 中的原型属性吗?
- Chrome 中的突变对象无法检测属性和 CSS 更改
- 为什么JavaScript包含属性在Chrome浏览器中不起作用
- Chrome - 即使先检查也无法读取未定义的属性“状态”
- 无法在Chrome的Javascript控制台中读取null的属性“style”
- “无法获取未定义或空引用的属性'getData'”在IE中,但不能在Chrome中获取
- Chrome I JavaScript 关于更改 CSS 中的显示属性的问题
- 在 Chrome 中获取新标签页的属性
- 我无法通过 Firefox 中的“for”属性访问标签,但可以在 Chrome 中访问标签
- Chrome,Safari - 未捕获的类型错误:无法读取 null 的属性“状态”