I have a website with pages A, B, C, D. On the start page - A - there is a html5 video, set to autoplay. So the vid starts on loading the page. The video plays once, showing a play-again-button on ending. That’s fine so far. If I visit page B or C and then go to A again, the video starts again. But I want to enable the autoplay only once per visitor. That’s how it should be: one visit the webpage, start on page A, see the video once, go to page B or C or D, go back again to A (using link or back-button); and find the play-again-button, not the video playing again.
Edit:
Thanks for the ideas using cookies; now I learned that over here in Europe there’s a law that you have to tell the visitor using cookies and give him a choice on the start page wether he wants to accept them.
So I want to use window.sessionStorage for that purpose.
This is my code telling the video to be set on autoplay=false and the play-again-button to be shown .on("ended", ...
$(document).ready(function () {
$("video").on("ended", function() {
$('video')[0].autoplay=false
$('video')[0].load()
$('.video-playing').removeClass('video-playing').addClass('video-wait');
$('.play').removeClass('hide_play');
});
$('.play').click(function(){
$('video')[0].play();
$('.video-wait').removeClass('video-wait').addClass('video-playing');
$('.play').addClass('hide_play');
});
});
HTML
<video id="header-video" class="video-playing" preload="auto" poster="">
<source src="" type="video/mp4">
<source src="" type="video/webm">
</video>
My goal is: going back from page B or C to the startpage - A - (see above) the class '.video-playing' should be set to '.video-wait', '.play' to 'hide_play' and autoplay to "false".
Using sessionStorage is best for me, I think, because on opening a new window it should start from the beginning.
Unfortunately I have no idea how to implement that sessionStorage in my code.