在html中完成视频后转到其他页面

时间:2016-10-28 07:19:48

标签: javascript html html5

我有这个页面:

    <!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="miscript.js"></script>
</head>
<body>
<div align="center">
        <video id="myvideo" autoplay>
           <source src="008.mp4" type="video/mp4">
            Your browser does not support html5 videos
        </video>
</div>      
</body>
</html>

我想看视频,完成后我想重定向到其他页面。

我正在尝试这个但是没有用。

miscript.js

document.getElementById('myvideo').addEventListener('ended',myHandler, false);
function myHandler(e) {
window.location="NewFile1.html";
};

任何想法??

2 个答案:

答案 0 :(得分:1)

&#13;
&#13;
var vid = document.getElementById("myvideo");
vid.onended = function() {

window.location.href="http://test.html/";

};
&#13;
<div align="center">
        <video id="myvideo" autoplay>
           <source src="008.mp4" type="video/mp4">
            Your browser does not support html5 videos
        </video>
&#13;
&#13;
&#13;

尝试不需要应用虚假

document.getElementById('myvideo').addEventListener('ended',myHandler);
function myHandler(e) {
window.location="NewFile1.html";
};

答案 1 :(得分:0)

jQuery:

$("#myvideo").bind("ended", function() {
   //code to run when video ended
   //redirect to http://stackoverflow.com
   window.location.replace("http://stackoverflow.com");
});

没有jQuery:

var videoObj = document.getElementById('myvideo');

videoObj.onended = function(e) {
  //code to run when video ended
  //redirect to http://stackoverflow.com
  window.location.replace("http://stackoverflow.com");
};

通过使用匿名函数添加事件侦听器:

document.getElementById('myvideo').addEventListener('ended', function(e) {

    //code to run when video ended
    //redirect to http://stackoverflow.com
   window.location.replace("http://stackoverflow.com");
})

页面重定向:

  window.location.replace("http://stackoverflow.com");

  window.location.href="http://stackoverflow.com";

注意:尝试在加载DOM后运行此代码。

 $(document).ready(function() { //Run from here });