【问题标题】:" iframe.contentDocument" Not Working in IE8 and FF(3.5 and below) any other steps to solve this?“iframe.contentDocument”在 IE8 和 FF(3.5 及更低版本)中不起作用还有其他解决此问题的步骤吗?
【发布时间】:2011-05-17 16:37:12
【问题描述】:
我在 js 文件上传器中使用了这个“iframe.contentDocument”,但它在 IE8 和 Firefox(3.5 及以下版本)中不起作用。
我如何通过使用其他 DOM 来处理 iframe 来解决这个问题?
谢谢大家
【问题讨论】:
标签:
javascript
iframe
uploader
【解决方案1】:
试试
var doc;
var iframeObject = document.getElementById('iframeID'); // MUST have an ID
if (iframeObject.contentDocument) { // DOM
doc = iframeObject.contentDocument;
}
else if (iframeObject.contentWindow) { // IE win
doc = iframeObject.contentWindow.document;
}
if (doc) {
var something = doc.getElementById('someId');
}
else {
alert('Wonder what browser this is...'+navigator.userAgent);
}