1

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.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
LEOPM
  • 51
  • 1
  • 2
  • 5

6 Answers6

1

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..

TheWolfNL
  • 1,263
  • 1
  • 13
  • 29
  • Sorry Folks, should have been more clear. Internet explorer is loading the js its just not carrying out all the functions, The aim of the script is to replace text pre existing in the page, also to remove a radio button option from the pre set form. All actions on the script are carried out successfully in chrome and firefox, however, only the remove radio button function is working in explorer, the replace function for the text is not carried out in explorer, thanks for your attention! – LEOPM Nov 27 '11 at 01:01
0

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

Radacina
  • 431
  • 5
  • 10
0

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
Dmitry Shvedov
  • 3,169
  • 4
  • 39
  • 51
0

Try:

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

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

GG.
  • 21,083
  • 14
  • 84
  • 130
  • Sorry Folks, should have been more clear. Internet explorer is loading the js its just not carrying out all the functions, The aim of the script is to replace text pre existing in the page, also to remove a radio button option from the pre set form. All actions on the script are carried out successfully in chrome and firefox, however, only the remove radio button function is working in explorer, the replace function for the text is not carried out in explorer, thanks for your attention! – LEOPM Nov 27 '11 at 00:58
  • What version of IE? The code is probably not compatible. Uses jQuery which is cross-browser. – GG. Nov 27 '11 at 01:14
0

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

kgautron
  • 7,915
  • 9
  • 39
  • 60
0

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.

Community
  • 1
  • 1
SynerCoder
  • 12,493
  • 4
  • 47
  • 78