Categories

innerHTML issue in IE

There are number of articles on internet that talk about the fix for the innerHTML issues in IE. some are

http://support.microsoft.com/kb/276228

http://domscripting.com/blog/display/99

None of these work when you try to insert javascript into the <script> tags. Thats because all these solutions talk about using a wrapper <div> for the content and it won’t work if you are trying to insert or modifiy the javascript inside the <script> tags.

The solution is instead of using ‘innerHTML’, use ‘text’ property.

var script = document.createElement('script');
script.type = 'text/javascript';
// IE doesn't support innerHTML, fails, and uses .text instead
try {
script.innerHTML = code;
} catch(e){
script.text = code;
}
document.getElementsByTagName('head')[0].appendChild(script);

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>