javascript HTML 视频结束后如何重定向到 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20008778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I redirect to a URL after a HTML video has ended?
提问by CAI_Innovator
I am trying to redirect to a different URL after a html video has ended. This cannot be using a FLASH player as it won't work on iOS devices. Any help or direction will be appreciated. Here is my code:
我正在尝试在 html 视频结束后重定向到不同的 URL。这不能使用 FLASH 播放器,因为它不适用于 iOS 设备。任何帮助或方向将不胜感激。这是我的代码:
<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>
回答by K3rnel31
回答by naw103
use window.location.replace('http://www.google.com'); so user dosnt get stuck in back button loops
使用 window.location.replace(' http://www.google.com'); 所以用户不会陷入后退按钮循环
<script>
var video1 = document.getElementsByTagName('video1')[0];
video1.onended = function(e) {
window.location.replace('http://www.google.com');
}
</script>
回答by HIRA THAKUR
Javascript:
Javascript:
document.getElementById('video-id').addEventListener('ended',function(){
window.location.href = 'http://www.your-url.com';
},false);
jQuery:
jQuery:
$("#video-id").on("ended", function() {
window.location.href = 'http://www.your-url.com';
});
Youtube:
YouTube: