October 6, 2011 Leave a comment
Its pretty straight forward,
- it first gets a reference to the head tag.
- Creates a script element using document.createElement
- Sets the source/url of the file
- Then sets the onload property of the script element to a callback function you supply. In i.e. it will check the onreadystatechange and execute the callback function you provide.
- And finally it appends the script element to the head of the page
Probably a million and one ways to do this but it works decently in I.E 7+,Firefox,Chrome,Safari and Opera