UNPKG

966 BJavaScriptView Raw
1export function isWindowObjectExist() {
2 return typeof window !== 'undefined';
3}
4export function loadScript(scriptUrl, onSuccess, onError, scriptId) {
5 if (!isWindowObjectExist()) {
6 return;
7 }
8
9 var head = document.getElementsByTagName('head')[0];
10 var script = document.createElement('script');
11 script.setAttribute('type', 'text/javascript');
12 script.setAttribute('src', scriptUrl);
13
14 if (scriptId) {
15 script.id = scriptId;
16 }
17
18 script.onload = function () {
19 if (onSuccess) {
20 onSuccess();
21 }
22 };
23
24 script.onerror = function (e) {
25 if (onError) {
26 onError("Unable to load script '".concat(scriptUrl, "'"), e);
27 }
28 };
29
30 head.appendChild(script);
31}
32export function loadScriptAsync(scriptUrl, scriptId) {
33 return new Promise(function (resolve, reject) {
34 loadScript(scriptUrl, function () {
35 resolve();
36 }, function (message, exception) {
37 reject(exception);
38 });
39 });
40}
41//# sourceMappingURL=dom.js.map
\No newline at end of file