antonin.lebrard
antonin.lebrard

Reputation: 139

My external javascript is not executed

I try to override the window.onload event inside an external javascript, but even when putting some basic console.log line outside the window.load function, the code seems to never execute.

Jumping to code here it is :
for index.html:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Canvas Experimentation</title>
    <script src="canvasEntry3D.js" type="type/javascript"></script>
</head>
<body>
    <canvas id="canvas" height="720" width="1280"></canvas>
</body>
</html>

for canvasEntry3D.js :

console.log("slkdfnsdnflknegs");
window.onload = abcdefg;
function abcdefg() {
     console.log("in start");
     var canvas = document.getElementById("canvas");
}

To really know if the browser has loaded the correct javascript file, I have already checked the developper console.

And I'm not searching to override two times the window.onlad event, so there's no need to use addEventListeners (and there is also no other javascript code that override the window.onload event)

Upvotes: 0

Views: 96

Answers (1)

Wa Kai
Wa Kai

Reputation: 466

The only mistake in your code I see is the wrong type attribute within your script tag.

Just change it from

<script src="canvasEntry3D.js" type="type/javascript"></script>

to

<script src="canvasEntry3D.js" type="text/javascript"></script>

Upvotes: 2

Related Questions