5

In my JavaScript I have a function detectEnvironmentAndGetLEAndDepot() which is called onload via HTML. I'm working with wicket, and need to take values held in the back-end, so I fire them to the screen, hide them, and search the <span> values from my JS for the name value, for example if(v.getAttribute('name') === 'LE'){do stuff} or if(v.getAttribute('name') === 'depot'){do stuff} (I'm sure not the most elegant solution, but I needed a quick one!). Then within the function detectEnvironmentAndGetLEAndDepot() I do a bit of formatting etc so the data is usable.

detectEnvironmentAndGetLEAndDepot() function (quite long, only relevant part) -

detectEnvironmentAndGetLEAndDepot = function() {

    Array.from(document.getElementsByTagName('span')).forEach(function(v) {

//Search name tag for particular names, then do formatting
}

When I open this in IE11 I get the error in a popup SCRIPT438: Object doesn't support property or method 'from' which is related to the first line of the method above - the Array class. Help much appreciated.

4 Answers 4

8

As Array.from method is not supported by IE, you can try to use:

[].slice.call(document.getElementsByTagName('span')).forEach(function(v) {});

This doesn't require usage of any 3rd party libraries.

Sign up to request clarification or add additional context in comments.

2 Comments

This seems to be working. However I changed my code back to Array.from - and it worked also. My app seems incredibly temperamental (in IE), sometimes it works sometimes it doesn't. On top of this, as soon as I open Developer Tools, everything breaks... I don't even have a starting position. I HATE IE.
@notAChance I've never used Angular, but I came across this when looking for help on the same issue (also using Array.from()). It sounds like your code's temperament could be related to the same issue; being loaded at the wrong time/before the document is loaded.
2

You could use an ES2015 polyfill, like es6-shim, Array.from or Babel polyfill

Comments

1

As explained by Mozilla here, the Array.from function is not yet supported by IE

Browser compatibility

Comments

1

you can use instead _underscore.js with function _.toArray(document.getElementsByTagName('span'))...

FYI:

'Array.from' not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.

source

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.