EN
JavaScript - on script load event
0 points
In this article, we would like to show you how to handle script load event using JavaScript.
Quick solution:
xxxxxxxxxx
1
<script>
2
3
function handleLoad() {
4
console.log('Script loaded.');
5
}
6
7
</script>
8
<script src="index.js" onload="handleLoad()"></script>
In this example, we add a function to the window.onload
property, which will be executed on successful script loading.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script>
5
6
function handleLoad() {
7
console.log('Script loaded.');
8
}
9
10
</script>
11
<script src="index.js" onload="handleLoad()"></script>
12
</head>
13
<body> Web page body... </body>
14
</html>
index.js
file:
xxxxxxxxxx
1
console.log('index.js text');
Result:
