Chinovski
Chinovski

Reputation: 517

How to make JS code works on IE8?

I have this code that works perfectly on Chrome, IE 11, but It doesn't on IE8, I tried to replace recent functions by old ones but I didn't got the same results as Chrome.

Well, this is the working script:

jsfiddle.net

I replaced the following functions wich are not supported by IE8:

getElementsByClassName() addEventListener() event oninput trim() firstElementChild textContent

This code doesn't work :(

jsfiddle.net

The problem I got is here

//Array.prototype.push.apply(grps, this.contener.getElementsByClassName('categorieDesAptitudes'));
Array.prototype.push.apply(grps, this.contener.querySelectorAll('.categorieDesAptitudes'));

// Code 

//while (html = grp.contener.firstElementChild) {
while (html = ( grp.contener.firstElementChild || grp.contener.children[0] || {}) ) {
    // data = html.getElementsByClassName('item-search')[0].textContent;
    data = (html.querySelectorAll('.item-search')[0].textContent || html.querySelectorAll('.item-search')[0].innerText);
    grp.items.push(this.addItem(html, data, idx_g));
}

I have errors like Cannot read property 'firstElementChild'

Does anyone has an idea how to resolve this? Thank you in advance

Upvotes: 1

Views: 126

Answers (1)

Andrei
Andrei

Reputation: 1216

The only suggestion that i have which might help you convert your code back over to valid js in ie could be the javascript compatability. JavaScript is based off the Ecma standard however ie8 is only compliant with es3 not es5 or es6. The best way i can think of is using typescript to enfore es3 rules.

So in the compile options i would set allowjs true and target to es3. I would also use a jslint tool in your ide/text edittor extension and make sure to set the target to es3 again, it'll tell you some things dont exists etc... This is great for massive projects as well but mind you there is lots to be fixed es3 was finalized like 16 years ago i think early 2000 / 99 so your bound to run into issues and the last suggestion i have i use polyfills for ie for es5 enviornment.

Upvotes: 1

Related Questions