Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- importScript: (function (head) {
- function loadError(error) {
- throw new URIError("The script " +
- error.target.src + " is not accessible.");}
- return function (url, callback) {
- var existingScript = document.querySelectorAll("script[src='" +
- url + "']");
- var isNewScript = (existingScript.length == 0);
- var script;
- if (isNewScript) {
- script = document.createElement("script")
- script.type = "text/javascript";
- }
- else {
- script = existingScript[0];
- }
- script.onerror = loadError;
- if (script.readyState) { //IE
- script.onreadystatechange = function () {
- if (script.readyState == "loaded" ||
- script.readyState == "complete") {
- script.onreadystatechange = null;
- if (callback) {
- callback(); }
- }
- };
- } else { // others than IE
- script.onload = callback; }
- if (isNewScript) {
- script.src = url;
- head.appendChild(script); }
- }
- })(document.head || document.getElementsByTagName("head")[0])
- importScript("myScript1.js");
- importScript("myScript2.js", /* onload function: */
- function () { alert("The script has been OK loaded."); });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement