<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>通过 JavaScript 实现全屏</h1>
<p>请单击按钮以全屏模式打开视频。</p>
<button onclick="openFullscreen();">以全屏模式打开视频</button>
<p><strong>提示:</strong>请按“Esc”键退出全屏。</p>
<video width="100%" controls id="myvideo">
<source src="/i/video/shanghai.mp4" type="video/mp4">
您的浏览器不支持 video 标签。
</video>
<script>
var elem = document.getElementById("myvideo");
function openFullscreen() {
if (
document.fullscreenEnabled ||
document.webkitFullscreenEnabled ||
document.msFullscreenEnabled
) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
}
}
}
</script>
<p>注释:Internet Explorer 10 及更早版本不支持全屏模式。</p>
</body>
</html>