9

我在 js 文件上传器中使用了这个“iframe.contentDocument”,但它在 IE8、Firefox(3.5 及以下版本)中不起作用。如何通过使用其他 DOM 与 iframe 一起使用来解决这个问题?

谢谢大家

4

1 回答 1

11

尝试

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);
}
于 2010-11-30T06:15:28.763 回答