I am trying to play a video on image click event. The device I am interesting in is the iphone. I want the iphone user, when comes to my site, to click on image and play the video on device native player. I have also tried video tag with poster but when the video ends and the user comes back to my site the poster is not showing anymore. I have tested with android device and there is no problem. That’s why I decided to make it work with onclick image event instead video tag.
Any help would be really appreciated if someone can help me, as I am looking for a workaround for weeks.
<!DOCTYPE html>
<div id="home01">
<img id="myImg" src="picture.jpg" width="640" height="360">
</div>
<script language="javascript" type="text/javascript">
document.getElementById('myImg').addEventListener('click', function (e) {
var video = document.createElement('video');
var sourceTag = document.createElement('source');
sourceTag.type = 'video/mp4';
sourceTag.src = 'rolex.mp4';
video.appendChild(sourceTag);
video.play();
});
</script>
</html>