REJH
REJH

Reputation: 3275

HTML <video> onended event not firing in Firefox 29

I'm having trouble getting the 'onended' event working in Firefox 29 for a HTML video element.

Here's some example code:

<video id="video"></video>

<script>
var video = document.getElementById("video");
video.onended = function() { alert('Ended'); }
video.play();
</script>

I left source files and such out of here so I do understand that the above example will never start playing but in my real code it does work.

Anyways. Firefox is not doing anything. It does fire onerror and oncanplay so I know I'm correctly binding the events...

Help?

Upvotes: 0

Views: 341

Answers (2)

REJH
REJH

Reputation: 3275

Ok I figured it out. Firefox doesn't like the 'video.onended = ...' syntax. It works for 'video.canplay = ...' but for onended it only works like this:

video.addEventListener("ended", function() {
    alert('Ended');
},false);

Not very consistent but a valuable life lesson: The web is not consistent. Ever.

Upvotes: 0

user2570812
user2570812

Reputation: 21

<video id="video"></video>

Your id "#video" does not match with getElementById("video")

Upvotes: 1

Related Questions