Javascript load script

To load a script dynamically using javascript, use the following code:

var scriptUrl = "http://google.com/myscript.js";

$("head").append("<script type=\"text/javascript\" src=\"" + scriptUrl + "\"></script>");

Note: This code snippet uses jQuery.

If you don’t have jQuery, use the following code (courtesy of Jan Wolter):

var head = document.getElementsByTagName("head")[0];

var script = document.createElement("script");
script.type = "text/javascript";
script.src = "helper.js";

head.appendChild(script);