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:
<script>
function handleLoad() {
console.log('Script loaded.');
}
</script>
<script src="index.js" onload="handleLoad()"></script>
Practical example
In this example, we add a function to the window.onload
property, which will be executed on successful script loading.
<!doctype html>
<html>
<head>
<script>
function handleLoad() {
console.log('Script loaded.');
}
</script>
<script src="index.js" onload="handleLoad()"></script>
</head>
<body> Web page body... </body>
</html>
index.js
file:
console.log('index.js text');
Result:
