LEOPM
LEOPM

Reputation: 51

internet explorer not reading Js file

I am using JavaScript to overwrite some preset options in my websites 3rd party shopping cart. The script work perfectly in Chrome and in Firefox, however, it does not work in Internet Explorer at all.

My script is <script src="http://www.amorame.com/geoff.js"></script>;

alert('test');
function x(){
    var y=document.forms[0].elements["pm"];
    var z;
    for (var j=0; j<y.length; j++) {
        z=y[j];
        if (z.value=="40") {
            z.style.display="none";
        }
    }
    document.body.innerHTML=document.body.innerHTML.replace("Payment by <b>Moneybookers</b> e-wallet<br>","");
    document.body.innerHTML=document.body.innerHTML.replace("Maestro, Visa and other credit/debit cards by <b>Moneybookers</b>","Pago con Diners Club, Mastercard o Visa");
}
onload=x;

I'm pretty new to JS and to be honest I just cant get my head around the answer to fixing this so IE will read the script.

Upvotes: 1

Views: 4224

Answers (6)

Dmitry Shvedov
Dmitry Shvedov

Reputation: 3286

IE seems to completely ignore files that have non-ES5 syntax somewhere in them. I did this to check for syntax compatibility:

npm install -g es-check
es-check es5 offendingFile.js

Upvotes: 0

Radacina
Radacina

Reputation: 441

I had the same symptoms with Internet Explorer. It all boiled down to an arrow function, unsupported by IE.

Upvotes: 0

SynerCoder
SynerCoder

Reputation: 12766

It is a bug in IE. If you alert the innerhtml you can see that it is replaced. But the browser doesn't reflect it.

Check this SO question: https://stackoverflow.com/questions/1293427/

You need to use more functions of the DOM to alter it. Here is a small snippet that generates a dom (my school assigment, so don't mind the dummy text):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title>Creating the Dom!</title>
    <link rel="stylesheet" type="text/css" href="createDom.css">
    <script type="text/javascript">

   function buildbody() 
   {
        var body = document.getElementsByTagName("body")[0];

        var theHeader = document.createElement('h1');
        var theHeaderTxt = document.createTextNode('Study program Bachelor of ICT');
        theHeader.appendChild(theHeaderTxt);
        body.appendChild(theHeader);

        var theHeader2 = document.createElement('h2');
        var theHeader2Txt = document.createTextNode('Introduction');
        theHeader2.appendChild(theHeader2Txt);
        body.appendChild(theHeader2);

        var txtN1 = document.createElement('p');
        var pTxt1 = document.createTextNode(
        'Western society is based on well functioning but rapidly changing technological applications.\n' +
        'However, mere specialisation is no longer enough modern technologistsneed to be capable of forming \n' +
        'a global overview of the developments in their branch. Accordingly, graduates from the Faculty of \n' +
        'Technology of University Drenthe are broadly educated technologists with an eye for innovation, \n' + 
        'management and social circumstances. The Faculty of Technology offers a four-year study program \n' +
        'Bachelor of ICT.');
        txtN1.appendChild(pTxt1);
        body.appendChild(txtN1); 

        var theHeader3 = document.createElement('h2');
        var theHeader3Txt = document.createTextNode('Course characters');
        theHeader3.appendChild(theHeader3Txt);
        body.appendChild(theHeader3);

        var pTxt2 = document.createTextNode(
        'Work is done on a problem-oriented, project basis, often involving external research, and the \n' +
        'practical training periods are completed at interesting positions in the relevant industries.');
        var txtN2 = document.createElement('p');
        txtN2.appendChild(pTxt2);
        body.appendChild(txtN2); 

        var theHeader4 = document.createElement('h2');
        var theHeader4Txt = document.createTextNode('Internship');
        theHeader4.appendChild(theHeader4Txt);
        body.appendChild(theHeader4);

        var pTxt3 = document.createTextNode(
        'In the third and fourth year students have the opportunity to put the theory into practice. \n' +
        'A company based traineeship of five months in the third year is part of the program and in the \n' +
        'fourth year students work on a final graduation project for one semester. Both periods can be \n' +
        'spent in the Netherlands or abroad.');
        var txtN3 = document.createElement('p');
        txtN3.appendChild(pTxt3);
        body.appendChild(txtN3); 

        var linkN1 = document.createElement('a');
        var linkTxt1 = document.createTextNode('Click for more information');
        linkN1.setAttribute('href','http://www.hbo-i.nl/default.aspx?pageID=24');
        linkN1.appendChild(linkTxt1);
        body.appendChild(linkN1);
   }
    </script>
  </head>
    <body onload="buildbody()">
    </body>
</html>

As you can see the body of the document is completely empty and the script generates it. You must also alter the dom in this manner.

Upvotes: 0

kgautron
kgautron

Reputation: 8263

It is probably the script not working under IE rather than not being 'read' by IE. Have you checked the IE javascript console?

Upvotes: 0

GG.
GG.

Reputation: 21844

Try:

<script type="text/javascript" src="http://www.amorame.com/geoff.js"></script>;

And see if the script works with an alert('test');

Upvotes: 0

TheWolfNL
TheWolfNL

Reputation: 1283

I never heard of IE not reading a js file, I normally verify by adding a simple line:

alert('test');

to check whether a file is loaded..

if you get the alert then the file is loaded but the code is not working properly for IE which would be more likely then IE not loading the JS at all..

Upvotes: 1

Related Questions