Any reason why the following code isn\'t working?
alert(\"1\");
document.head.appendChild(\"
element.appendChild
expects a node not a string. You should first create the node and set the attributes and then append it.
element.appendChild Reference
var sc = document.createElement("script");
sc.setAttribute("src", "https://getfirebug.com/firebug-lite.js");
sc.setAttribute("type", "text/javascript");
document.head.appendChild(sc);
For older browsers (IE < 9 etc.) that doesn't support document.head
document.getElementsByTagName("head")[0].appendChild(sc);
This will do what the original poster wants without creating a new object.
document.head.innerHTML += "<script type=\"text/javascript\" src=\"https://getfirebug.com/firebug-lite.js\"></script>";
The script will be appended to the end of the existing head section which may not be what you want.
Believe it or not this will put your script at the start of the head section without erasing the existing head section:
document.head.innerHTML = "<script type=\"text/javascript\" src=\"https://getfirebug.com/firebug-lite.js\"></script>" + document.head.innerHTML;