2

I'm kind of new with programming in web and I'm trying to figure out how to reset the video after playing it for the first time. My code is:

var video = document.getElementById('home_video');
    video.addEventListener('click',function(){
    video.play();
},false);

Thank you!

Anonymous
  • 10,002
  • 3
  • 23
  • 39
user3754764
  • 23
  • 1
  • 4

3 Answers3

3

I believe you can use something like this:

var video = document.getElementById('home_video');
    video.addEventListener('click',function(){
    video.currentTime = 0
    video.play();
    },false);
M O H
  • 284
  • 3
  • 15
  • it works on Chrome but not on Mozilla is there any settings when using different browsers? – user3754764 Sep 12 '14 at 02:17
  • I think there is a can play event that fires when it is ready to play. Something like this: video.addEventListener("canplay",function() { video.currentTime = 0;}); – M O H Sep 12 '14 at 13:43
1

I think you should be able to do it with video.currentTime = 0;

http://www.w3schools.com/tags/av_prop_currenttime.asp

Jazzepi
  • 5,259
  • 11
  • 55
  • 81
1

Add video.load();

Your Code after changes:

var video = document.getElementById('home_video');
  video.addEventListener('click',function(){
  video.load();
  video.play();
  },false);
Jatin
  • 3,065
  • 6
  • 28
  • 42