9/17/2008

Injection Javascript with innerHTML

When you create 'javascript' dynamically in IE, you need to work with HTMLDom Element.
This is the way simple way to insert 'Javascript' in IE, using [element].innerHTML.

According to MSDN, there is the attribute 'defer' for Script Element supporting inline script available when element inserted. By the way there is a small problem, IE recognizes script element as source for innerHTML only after Text element.

This is the example.

var container = document.getElementById("id");
var resultDocument = "<script defer='true' >.......</script>";
var dummyTag="<div style='display:none;position:absolute;top:0px;left:0px;'> </div>";
container.innerHTML = dummyTag+resultDocument;

This works for only inline script, if you want to insert script source, create script element and insert into 'Head  Element'


Enjoy 'javascript' ~~~~