Leustad
Leustad

Reputation: 385

onload event is not firing

I've implemented this answer in order to solve my problem but I still can't get the onload event fire.

I need a javascript solution, and I'm trying this on chrome. I know that I need to check for readystate for IE.

What am I missing here?

<script>
        var script = document.createElement('script');
        script.type = "type/javascript";
        document.getElementsByTagName('head')[0].appendChild(script);

        script.onload = function(){
            console.info("After loading");
            mdp.video.loadAllPlayers(".videoPlaceholder");
        };

        script.src = "/source.min.js";
</script>

Upvotes: 1

Views: 1724

Answers (1)

MMK
MMK

Reputation: 3721

Something like that

<!DOCTYPE html>
<html>

<head>

</head>

<body>
  <script type="application/javascript">
    var el = document.createElement('script');
    el.src = "//cdnjs.cloudflare.com/ajax/libs/less.js/1.3.3/less.min.js"; // use what ever js file you want but valid one
    el.onload = function(script) {
      console.log(script + ' loaded!');
    };

    document.body.append(el);
  </script>
</body>

</html>

Upvotes: 2

Related Questions