2013-11-15 27 views
0

我試圖在html視頻結束後重定向到不同的URL。這不能使用FLASH播放器,因爲它不適用於iOS設備。任何幫助或方向將不勝感激。這裏是我的代碼:如何在HTML視頻結束後重定向到URL?

<head> 
<script type="text/javascript"> 
    myVid = document.getElementById("video1"); 
    function redirect() 
    { 
     if (myVid.ended == true) { 
      window.location = "http://www.google.com"; 
     } 
</script> 
</head> 
<body> 
    <video id="video1" controls="controls"> 
     <source src="video.mp4" type="video/mp4"> 
     Your browser does not support HTML5 video. 
    </video> 
</body> 

+0

'myVid.addEventListener(」冒犯',功能( e){window.location.href ='http://www.google.com'; }); '? – putvande

回答

2

設置視頻的ID爲 'myvid' 這裏纔是解決

video = document.getElementById('myvid'); 
video.addEventListener('ended',function() {alert('video is ended');  
window.location.href = 'http://www.google.com';}) 

這裏是demo

+0

我還是有點卡住了。視頻在完成播放後沒有重定向。 –

+0

@CAI_Innovator讓我知道這 – K3rnel31

+0

@CAI_Innovator jsfiddle不能重定向,但ir工作正常,我已測試它 – K3rnel31

0

使用window.location.replace('http://www.google.com');所以用戶dosnt陷入後退按鈕循環

<script> 
    var video1 = document.getElementsByTagName('video1')[0]; 

    video1.onended = function(e) { 
     window.location.replace('http://www.google.com'); 
    } 
</script> 
0

的Javascript:

document.getElementById('video-id').addEventListener('ended',function(){ 
    window.location.href = 'http://www.your-url.com'; 
},false); 

的jQuery:

$("#video-id").on("ended", function() { 
     window.location.href = 'http://www.your-url.com'; 
    }); 

的Youtube:

How to detect when a youtube video finishes playing?