Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadScript(url, callback)
- {
- // Adding the script tag to the head as suggested before
- var head = document.getElementsByTagName('head')[0];
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = url;
- // Then bind the event to the callback function.
- // There are several events for cross browser compatibility.
- script.onreadystatechange = callback;
- script.onload = callback;
- // Fire the loading
- head.appendChild(script);
- }
- Then you write the code you want to use AFTER the script is loaded in a lambda function:
- var myPrettyCode = function() {
- // Here, do what ever you want
- };
- Then you run all that:
- loadScript("my_lovely_script.js", myPrettyCode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement