0

How to run this on IE8?

var innerdoc = document.getElementsByTagName('iframe')[2].contentDocument;

I can't use jQuery neither getElementsById().

Adam Azad
  • 11,171
  • 5
  • 29
  • 70
ameliapond
  • 218
  • 4
  • 18

1 Answers1

1

According to MDN, the contentDocument property is not supported in IE8.

To work around that, you could access .contentWindow.document instead:

var element = document.getElementsByTagName('iframe')[2],
    innerDoc = null;

if (element.contentDocument) {
  innerDoc = element.contentDocument;
} 
else if (element.contentWindow) { // IE fallback
  innerDoc = element.contentWindow.document;
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304