1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html>
  5. <head>
  6. <title>Dynamically Loading JavaScript :: InnerHTML :: Does Not Work in IE6</title>
  7. <script type="text/javascript">
  8. var myInnerHTML = "var foo = \"Dynamically loaded JavaScript!\"; alert(foo); function showHtml() { var html = document.getElementsByTagName(\"html\")[0]; alert(html.innerHTML); }";
  9.  
  10. function dynamicLoadJS()
  11. {
  12. var head = document.getElementsByTagName("head")[0];
  13. var scrpt = document.createElement("script");
  14. scrpt.id = "DynaScript";
  15. scrpt.type = 'text/javascript';
  16. head.appendChild(scrpt);
  17. try {
  18. scrpt.innerHTML = myInnerHTML;
  19. } catch (expt) { alert(expt.name); alert(expt.message); return;}
  20.  
  21. document.getElementById("LoadJS").disabled="true";
  22. document.getElementById("CallJS").disabled="";
  23. }
  24. </script>
  25. </head>
  26. <body>
  27. <button id="LoadJS" onclick="dynamicLoadJS();">Load JavaScript</button>
  28. <button id="CallJS" onclick="showHtml();" disabled="disabled">Call method from new load</button>
  29. </body>
  30. </html>
  31.  
  32.