Why does forEach() not work in an iframe in IE11?

10,722

"IE11 uses Quirks Mode emulation if the top-level page is not in Edge Mode." - MSDN

In this mode, arrays don't support the forEach method.

Use a simple for loop instead, or write this right after the title tag of the parent:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
Share:
10,722
Tamás Bolvári
Author by

Tamás Bolvári

Updated on June 13, 2022

Comments

  • Tamás Bolvári
    Tamás Bolvári almost 2 years

    This question was closed as off-topic, so I've marked the missing info.

    Specific problem or error plus shortest code neccesary:

    The code below doesn't work in IE11, if it's in an iframe of certain websites. ("Certain" is not specific, but I don't have a public demo. I can't make one, until I find the cause in my private code. Still, the question is specific enough to be answered by an expert, that's why I've asked SO instead of a long debugging process without any idea.)

    ['a', 'b'].forEach(function(elem){console.log(elem);});
    

    The error says that the array doesn't support the forEach method.

    Desired behavior:

    The forEach() method executes a provided function once per array element. - MDN

  • Chexpir
    Chexpir over 7 years
    Remember, avoid using IE=edge unless you are sure what you are doing. stackoverflow.com/questions/14611264/… gwtproject.org/doc/latest/DevGuideIE9.html
  • Yes Barry
    Yes Barry about 5 years
    I disagree, I say avoid not using IE=edge :)