document.documentElement.msRequestFullscreen() returns undef



我正在尝试在ie11上使用document.docentElement.msRequestFullscreen((进行全屏显示。它返回undefined。

还有

var elem = document.getElementById("ember715"); 
elem.msRequestFullscreen()

在ie11上返回undefined。P.S-elem.requestFullscreen((在chrome中完成了这项工作,因此elem得到了正确的定义。我借用了如何启用IE全屏功能,如firefox和chrome

我建议您使用下面的代码进行测试。我用IE 11测试了它,它运行良好。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>Fullscreen with JavaScript</h2>
<p>Click on the button to open the video in fullscreen mode.</p>
<button onclick="openFullscreen();">Open Video in Fullscreen Mode</button>
<p><strong>Tip:</strong> Press the "Esc" key to exit full screen.</p>
<video width="100%" controls id="myvideo">
<source src="https://www.w3schools.com/jsref/rain.mp4" type="video/mp4">
<source src="sample.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<script>
/* Get the element you want displayed in fullscreen */ 
var elem = document.getElementById("myvideo");
/* Function to open fullscreen mode */
function openFullscreen() {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
}
</script>
<p>Note: Internet Explorer 10 and earlier does not support fullscreen mode.</p>
</body>
</html>

参考:

HTML DOM requestFullscreen((方法

最新更新