...

View Full Version : Dynamically Add Javascript Code Problem



Petty_Crim
05-18-2009, 01: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';
script.innerHTML=js_string;
head.appendChild(script);

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?

Petty_Crim
05-18-2009, 01: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum