Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 353
Tamás Bolvári Avatar asked Dec 26 '22 02:12

Tamás Bolvári


1 Answers

"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" />
like image 83
Tamás Bolvári Avatar answered Dec 27 '22 16:12

Tamás Bolvári