Type your custom Javascript Code:
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<script type="text/javascript"> /** * @param tagAttributesObj keyvalue object with the attributes of the script tag * @param codeAsTex a string that contains the javascript code * @param divName The div ID where the script is going to be inserted (optional) * @return {Number} Id of the script tag */ function appendScript(tagAttributesObj, codeAsText, divName){ var newScript = "<span style='display:none;'>.</span>"; // Create openning tag var tagId = "scriptId" + Math.ceil(Math.random() * 10000); if(tagAttributesObj != null){ newScript += "<SCRIPT id='"+ tagId +"' "; for(var a in tagAttributesObj){ newScript += a +"='"+ tagAttributesObj[a] +"' "; } newScript += "DEFER>"; }else{ newScript += "<SCRIPT type='text/javascript' DEFER>"; } // Add new script if(codeAsText != null) newScript += codeAsText; // Close script tag newScript += "</SCRIPT" + ">"; // Append to DOM if(divName != null){ var container = document.getElementById(divName); container.innerHTML = newScript; }else{ var container = document.createElement("div"); container.innerHTML = newScript; document.body.appendChild(container); } return tagId; } function insertCustomScript(){ var txt = document.getElementById('ta'); var scr = txt.value; appendScript(null, scr); } </script> |