2

I have a video and I want to save the current time in a variable on browser refresh/close/back, for this I am using window.onload = function() function and every half sec getting the current time of the video, but when I refresh the page window.onload = function() have no time1 "current value".

var time1=10;
window.setInterval(function(){
  var vid1 = document.getElementById("myVideo");
  time1=Math.round(vid1.currentTime);
  alert(time1);
}, 500);

window.onload = function(){ alert('Working!! : '+time1); }
<a href="#" id="playvideo" onclick="pause_play()"> 
  <video id="myVideo" width="640" height="267" poster="media/cars.png">
    <source src="media/cars.mp4" type="video/mp4">
  </video>
</a>
tom
  • 21,844
  • 6
  • 43
  • 36
  • When the page is refreshed the JS is reset/refreshed too. If you want to store values between page refreshes you can't do it with a variable, you should use `localStorage`. – nnnnnn Aug 30 '17 at 03:14
  • if you want to get the timer value when you are moving from page to another / refresh / back. you can use WindowEventHandlers.onbeforeunload method. In this method get the video player current time and store and you can use it . for storing and retrieving in multiple pages you can use Local/session storage. – Hariharan Subramanian Aug 30 '17 at 03:21

0 Answers0