I just now started using jquery-3.3.1, and my onload(); function not working anymore. I know this is updated, so I changed the window.onload = function(e)
to $(window).on("load", function (e)
, but not working... Whats the wrong with this code? How can I call the load function now?
$(window).on("load", function (e) {
var videoSource = new Array();
videoSource[0] = 'video1.mp4';
videoSource[1] = 'video2.mp4';
var i = 1; // define i
var videoCount = videoSource.length;
function videoPlay(videoNum) {
document.getElementById("myVideo").setAttribute("src", videoSource[videoNum]);
document.getElementById("myVideo").load();
document.getElementById("myVideo").play();
}
document.getElementById('myVideo').addEventListener('ended', myHandler, false);
videoPlay(0); // play the video
function myHandler() {
i++;
if (i == (videoCount - 1)) {
i = -1;
videoPlay(0);
} else {
i = 0;
videoPlay(1);
}
}
})
and this is my html:
<video playsinline autoplay muted id="myVideo" type="video/mp4" onload="onload();" poster="poster.png"></video>
SOLVED: the problem originate from that, I use this window.onload = function()
before an (or the?) $(document).ready(function()
... Sorry guys, I am very in javascript, just now learning the basics of this language. Now works the all your solutions, thank you very much all your replies!