document.documentElement.msRequestFullscreen()返回未定义

问题描述 投票:0回答:1

我正在尝试在ie11上使用document.documentElement.msRequestFullscreen()进入全屏模式。返回未定义。

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

在ie11上返回未定义。P.S- elem.requestFullscreen()在chrome中完成工作,因此正确定义了elem。我从这里借来的How to enable IE full-screen feature like firefox and chrome

javascript internet-explorer iframe internet-explorer-11 fullscreen
1个回答
1
投票

我建议您使用以下代码进行测试。我用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() Method

© www.soinside.com 2019 - 2024. All rights reserved.