Is there some equivalent to jQuery's getScript in Prototype ?
1 Answer
var head;
var script;
head = $$('head')[0];
if (head)
{
script = new Element('script', { type: 'text/javascript', src: 'dynamic.js' });
head.appendChild(script);
}
3 Comments
Phonethics
Im loading this script after a user interaction, so I dont think inserting in head would execute it, would it ? Anyway, I've used native JS to add this. Hopefully this works in all browsers. var fileref = document.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", "domain.com/script.js");
Sebastian Sastre
Cool, now is there a onComplete? how can I detect when it finishes loading?
Ali Habibzadeh
That was 2010, leave these stuff and move to Angular, Backbone etc. Also look at script loading with require.js if you just need to add script modules