View Full Version : Dynamically Add Javascript Code Problem

05-18-2009, 02:30 PM
I am making an ajax website that dynamically adds javascript and css code to pages.

My code is as follows:

var head = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.id = 'content_script';
script.type = 'text/javascript';

This works fine and does as expected in Firefox. However in Internet Explorer (IE 6) it does not like it and gives me the ever helpful error msg "unknown runtime error" :rolleyes:

I have tried script.appendChild(js_string) but that gives me errors in both browsers.

Does anyone know what the way to do it in IE is?

05-18-2009, 02:49 PM
Ok updated. I have worked out how to do add the javascript code you use script.text=js_string;

However css_tag.text="css code" is not working.