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 :: Text Property :: Works 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. scrpt.text = myInnerHTML;
  18.  
  19. document.getElementById("LoadJS").disabled="true";
  20. document.getElementById("CallJS").disabled="";
  21. }
  22. </script>
  23. </head>
  24. <body>
  25. <button id="LoadJS" onclick="dynamicLoadJS();">Load JavaScript</button>
  26. <button id="CallJS" onclick="showHtml();" disabled="disabled">Call method from new load</button>
  27. </body>
  28. </html>
  29.  
  30.