I have a django template page with a youtube video player that looks like this:
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: window.innerHeight - 20,
width: window.innerWidth - 20,
videoId: '{{video}}',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.setPlaybackQuality('hd1080');
event.target.playVideo();
}
function onPlayerStateChange(event) {
if (event.data == 0) {
document.getElementById('choices').style.display = "block";
}
}
</script>
<div id="choices" class="choiceBox">
Which direction?<br>
<a href="/pedestrian/video/{{ subID }}/{{ condition }}/{{ trial }}/storeChoice/left/">Left</a><br>
<a href="/pedestrian/video/{{ subID }}/{{ condition }}/{{ trial }}/storeChoice/right/">Right</a>
</div>
It all works and is nothing complicated. I have a div that is hidden until the video stops playing. What I would like to do is get the unix time in milliseconds as soon as one of the 2 hidden links are clicked and store that into a variable. Finally, Id like to attach that as a post parameter in both of the URLs (concatenate ?=time onto the end of the url)
Any idea on how this might be achieved? The issue that I can get the time as soon as the video stops, but it wont add it onto the url presumably because the url has already been written once the page loads the first time. Is it possible to modify that url after the fact?