(url: string, jsId?: string)
| 1 | export const loadScript = (url: string, jsId?: string) => { |
| 2 | return new Promise(function (resolve, reject) { |
| 3 | const scriptId = jsId || 'de-fit2cloud-script-id' |
| 4 | let dom = document.getElementById(scriptId) |
| 5 | if (dom) { |
| 6 | dom.parentElement?.removeChild(dom) |
| 7 | dom = null |
| 8 | } |
| 9 | const script = document.createElement('script') |
| 10 | |
| 11 | script.id = scriptId |
| 12 | script.onload = function () { |
| 13 | return resolve(null) |
| 14 | } |
| 15 | script.onerror = function () { |
| 16 | return reject(new Error('Load script from '.concat(url, ' failed'))) |
| 17 | } |
| 18 | script.src = url |
| 19 | const head = document.head || document.getElementsByTagName('head')[0] |
| 20 | ;(document.body || head).appendChild(script) |
| 21 | }) |
| 22 | } |
no test coverage detected