0

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)

9
  • Are you sure the path is correct? Do you get any 404 errors in the console? Commented Apr 13, 2016 at 9:23
  • I was thinking of that too, but in the developper console, when I look for the network tab, it show exactly the canvasEntry3D.js that I have in my workspace. Commented Apr 13, 2016 at 9:26
  • So no 404 and yes canvasEntry3D.js is in the same folder as my index.html Commented Apr 13, 2016 at 9:27
  • 1
    @gurvinder372 I don't think it is a duplicate, in the question you linked he was using two onload functions, and the second one was overriding the first one. Commented Apr 13, 2016 at 9:29
  • 2
    Try to change your script attribute to 'text/javascript' from 'type/javascript' Commented Apr 13, 2016 at 9:34

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Ha Ha. Awesome Wa kai. You eye power is really great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.