This code do not work in IE?

Discussion in 'Javascript' started by Thomas Jansen, Aug 3, 2007.

  1. Hi,

    IE reports an unknown error with this code.
    But with Firfox and Opera there is no problem running the code.
    Any hint why?

    // response = var sMessage = "Hello, ";| var sName = "Your Name";|
    callback(sMessage + sName);
    var response = decodeURIComponent(http.responseText);
    alert(response);
    var olist = response.split('|');

    var s = document.createElement("script");
    s.type = "text/javascript";
    s.innerHTML = (olist[0]);
    s.innerHTML += (olist[1]);
    s.innerHTML += (olist[2]);
    document.body.appendChild(s);

    ~TJ
    Thomas Jansen, Aug 3, 2007
    #1
    1. Advertising

  2. Thomas Jansen wrote:

    > IE reports an unknown error with this code.
    > But with Firfox and Opera there is no problem running the code.
    > Any hint why?



    > var s = document.createElement("script");
    > s.type = "text/javascript";
    > s.innerHTML = (olist[0]);
    > s.innerHTML += (olist[1]);
    > s.innerHTML += (olist[2]);
    > document.body.appendChild(s);


    IE allows you to create most elements with createElement but is a bit
    picky about other actions like appendChild or setting innerHTML when it
    comes to script or style elements. You should be able to set the text
    property of script elements in IE, Opera, Mozilla e.g.

    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.text = 'alert("foo");';
    document.body.appendChild(script);

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 3, 2007
    #2
    1. Advertising

  3. Martin Honnen skrev:
    > Thomas Jansen wrote:
    >


    > var script = document.createElement('script');
    > script.type = 'text/javascript';
    > script.text = 'alert("foo");';
    > document.body.appendChild(script);
    >


    Thank you scripts.text was the solution.

    ~TJ
    Thomas Jansen, Aug 3, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. craig dicker
    Replies:
    9
    Views:
    672
    Juan T. Llibre
    Jul 7, 2005
  2. TB
    Replies:
    2
    Views:
    3,728
  3. Evan
    Replies:
    1
    Views:
    393
    Joe Riopel
    Sep 12, 2007
  4. jcvoon
    Replies:
    0
    Views:
    360
    jcvoon
    Nov 6, 2007
  5. Koh
    Replies:
    2
    Views:
    193
    Thomas 'PointedEars' Lahn
    May 11, 2004
Loading...

Share This Page