-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path59.js
30 lines (23 loc) · 902 Bytes
/
59.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
function loadScript(src, callback, name){
let script = document.createElement('script')
script.src = src
document.head.append(script)
// .onload property
script.onload = ()=>{
callback(null,src,name) // we are going to keep the format of callback function like hello(error,url,name)
}
// .onerror property
script.onerror = ()=>{
callback(new Error('Error on loading '+name+' src : '+src),src,name) // just passing arguments to the function that will be passed as callback
}
}
function hello(error,url,name){
if(error){
console.log(error)
}
else{
console.log('Script loaded '+name+' url '+url)
}
}
loadScript('https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js',hello,'Bootstrap1') // will be loaded
loadScript('https://hakallaka',hello,'Bootstrap2') // will give error