-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadScript.js
42 lines (39 loc) · 1.47 KB
/
loadScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Create a scriipt element in head of HTML and put /soap/ajax/31.0/connection.js in the src */
var connectJsUrl = "https://" + window.location.host + "/soap/ajax/32.0/connection.js";
function loadScript(url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
var done = false;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
callback();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
loadScript(connectJsUrl, function() {
console.log("Script Confirmed...");
});
/* Check to see if the file have been appended correctly and works correctly */
/*var JSFile = "https://" + window.location.host + connectJsUrl;*/
var req = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
if (req == null) {
console.log("Error: XMLHttpRequest failed to initiate.");
};
req.onload = function() {
try {
eval(req.responseText);
} catch (e) {
console.log("There was an error in the script file.");
}
};
try {
req.open("GET", connectJsUrl, true);
req.send(null);
} catch (e) {
console.log("Error retrieving data httpReq. Some browsers only accept cross-domain request with HTTP.");
};