html - 播放后关闭/隐藏视频
问题描述
我的网站上有一个全角自动播放静音 mp4。我希望它在到达末尾时关闭/隐藏 - 而是显示一个表单。那可能吗?也许通过自动重定向到另一个页面,如果另一个不是一个选项。
<div class="videoWrapper">
<video controls autoplay muted>
<source src="https://www.tectonicentertainment.com/wp-content/uploads/2019/09/TECTONIC.mp4" type="video/mp4">
Your browser does not support the video tag
</video>
解决方案
“我希望它在到达末尾时关闭/隐藏 - 而是显示一个表单。这可能吗?也许通过自动重定向到另一个页面,如果另一个页面不是一个选项。”
(1)检测视频结尾添加onended
到您的视频标签。例子: onended="doSomeFunctionName()"
(2)更新一个<div>
使用innerHTML
,或者重定向页面使用window.location.replace
可测试的例子:(注意<div>
已经给了一个ID,所以我们知道要更新哪个东西)
<!DOCTYPE html>
<html>
<body>
<div id="myVidContainer" class="videoWrapper">
<video controls autoplay muted onended="myVideoFinished()">
<source src="https://www.tectonicentertainment.com/wp-content/uploads/2019/09/TECTONIC.mp4" type="video/mp4">
Your browser does not support the video tag
</video>
</div>
<script>
function myVideoFinished()
{
alert("The video has ended");
//# create FORM code in some string
var form_code = "<form action='/action_page.php' method='get'>"
form_code += "First name: <input type='text' name='fname'><br>"
form_code += "Last name: <input type='text' name='lname'><br>"
form_code += "<input type='submit' value='Submit'>"
form_code += "</form>"
//# replace Video tag with Form
document.getElementById("myVidContainer").innerHTML = form_code;
//# or Redirect to another page
//window.location.replace("https://www.google.com")
}
</script>
</body>
</html>
推荐阅读
- mysql - LEFT JOIN 四个表,结果不需要
- twitter-bootstrap - 如何在 Bootstrap 4.1.3 中正确使用选项卡
- java - Android解析xml不起作用空输出
- c++ - 可以在智能指针管理的内存上创建新的位置吗?
- python - Python server that can act as client too
- regex - Go 中跨越多行的正则表达式
- javascript - Symfony:在 RuntimeException 中使用 put 请求获取路由结果
- mongodb - 使用正则表达式的 Mongo 聚合查询组
- mysql - 将帖子和评论存储在单独的表中或一起
- c# - 正确地将字符串从 C# 编组到 C++