我试图知道用户何时全屏显示 div 或不使用fullscreenchange
Javascript。该脚本适用于 Chrome(设置全屏 div,显示警报,然后在关闭全屏时再次显示警报)但不适用于 Firefox。为什么?
<!DOCTYPE html>
<head>
<meta content="text/html; Charset=UTF-8" http-equiv="Content-Type" />
<title>test fullscreenchange </title>
</head>
<body>
<div id="macarte" class="csscarte" style="color: green" >my div</div>
<button onclick="goFullscreen('macarte'); return false">showfullscreen</button>
<script type="text/javascript">
function fullscreenouinon() {alert("Full Screen Change !");};
function goFullscreen(id) {
// Get the element that we want to take into fullscreen mode
var thediv = document.getElementById(id);
// These function will not exist in the browsers that don't support fullscreen mode yet,
// so we'll have to check to see if they're available before calling them.
if (thediv.requestFullScreen) {
//fonction officielle du w3c
thediv.addEventListener("fullscreenchange", function() {fullscreenouinon()}, false);
thediv.requestFullScreen();
} else if (thediv.webkitRequestFullScreen) {
//fonction pour Google Chrome (on lui passe un argument pour autoriser le plein écran lors d'une pression sur le clavier)
thediv.addEventListener("webkitfullscreenchange", function() {fullscreenouinon()}, false);
thediv.webkitRequestFullScreen(thediv.ALLOW_KEYBOARD_INPUT);
} else if (thediv.mozRequestFullScreen){
//fonction pour Firefox
thediv.addEventListener("mozfullscreenchange", function() {fullscreenouinon()}, false);
thediv.mozRequestFullScreen();
} else {
alert('Votre navigateur ne supporte pas le mode plein écran, il est temps de passer à un plus récent ;)');
}
};
</script>
</body></html>