EN
JavaScript - handle css file loading error
3 points
In this article, we would like to show you how to handle .css
file loading error using JavaScript.
In this example, we handle .css
file loading error by assigning handleError()
function to the link element onerror
attribute.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script>
5
6
function handleError() {
7
console.error('.css file loading error.');
8
}
9
10
</script>
11
<link rel="stylesheet" type="text/css" href="/invalid/path/to/file.css" onerror="handleError()" />
12
</head>
13
<body> Web page body here... </body>
14
</html>