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>