This code do not work in IE?

T

Thomas Jansen

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
 
M

Martin Honnen

Thomas said:
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);
 
T

Thomas Jansen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top