0

If I put a script tags <script src="url"></script> in the head section of the page like

<html>
  <head>
    <script src="url1"></script>
    <script src="url2"></script>
    <script src="url3"></script>
    <script src="url4"></script>
  </head>
</html>

if some of them has failed to load, how can I detect the same and alert the user like

function scriptLoadFailed( url )
{
   alert( url + " loading failed!" );
}

Thanks in advance.

1

1 Answer 1

3

At the top of your <head>

<script>
    function scriptfail(element) {
        alert('failed to load ' + element.src);
    }
</script>

In your script element

<script src="url1" onerror='scriptfail(this);'></script>
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.