我試圖知道用戶在全屏幕中顯示div或不在javascript中使用fullscreenchange。此腳本適用於Chrome(設置全屏div,顯示提示,然後當關閉全屏時,再次顯示提醒),但不適用於Firefox。爲什麼?firefox上的javascript mozfullscreenchange
<!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>