troubleshooting Question

Using innerHTML to insert html code that contains script tag

Avatar of aidinet
aidinet asked on
Web Languages and StandardsJavaScriptWeb Browsers
2 Comments1 Solution1854 ViewsLast Modified:
My problem is exactly the same issue in this article:
http://poeticcode.wordpress.com/2007/10/03/innerhtml-and-script-tags/
"I have a requirement where I get some HTML snippet through Ajax request and then update a div area. So far so good. The HTML snippet needed to have some JavaScript"
Knowing that the JavaScript in the HTML snippet is trusted, It should be executed after inserting it in the div area.
As in the article, I use appendChild to insert the HTML into the div, in the case of Firefox, and user defer attribute to the scripts tags come in the HTML snippet in the case of IE.

It works will but I discovered that the script is not executed always in the IE.

Is there a solution (OTHER than using eval) to ensure that the script attribute will always executed on IE.

Thanks


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros