My Browser: Google Chrome Version 33.0.1750.154 m
Script:
function exitFullscreen() {
var element = document.documentElement;
if (element.mozCancelFullScreen) {
element.mozCancelFullScreen();
} else if (element.webkitExitFullScreen) {
element.webkitExitFullScreen();
} else if (elem.exitFullScreen) {
element.exitFullScreen();
} else if (elem.msExitFullScreen) {
element.msExitFullScreen();
}
}
HTML:
<div class="menubutton" style="width: 100px;" onclick="exitFullscreen();">
<span class="menubuttontext">EXIT FULLSCREEN</span>
</div>
but when I press that div in fullscren mode nothing happens, did I do a typo, wrote the code totally wrong or is it not possible?
Alternate Soultion? If that div button onclick can trigger a keyboard press escape key it can exit fullscreen too, or is this not possible?
There is a typo in (though it won't solve the issue)
} else if (elem.exitFullScreen) { // should be element
element.exitFullScreen();
} else if (elem.msExitFullScreen) {
element.msExitFullScreen();
}
But the exitFullscreen
should be called on document
object only
function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With