christophe christophe - 3 years ago 304
Javascript Question

Fullscreen API in webkit browser

I am working on a toggle for the JavaScript Fullscreen API. Somehow the exit fullscreen mode (the else statement) in Webkit Browser doesn't work. Can someone hint what is wrong? The code is the example code of the Mozilla Documentation of the fullscreen API.
var toggleFullScreen;

toggleFullScreen = function() {
if ((document.fullScreenElement && document.fullScreenElement !== null) || (!document.mozFullScreenElement && !document.webkitFullScreenElement)) {
if (document.documentElement.requestFullScreen) {
return document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
return document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
return document.documentElement.webkitRequestFullScreen();
} else {
return console.log("didnt happen");
} else {
if (document.cancelFullScreen) {
console.log("Mozilla Proposal cancels Fullscreen");
return document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
console.log("Firefox closes");
return document.mozCancelFullScreen();

// This is the line:

} else if (document.webkitCancelFullScreen) {
console.log("Webkit closes");
return document.webkitCancelFullScreen();
} else {
return console.log("Can't close");

Answer Source

Have a look here ... This is the page I use when Im referencing fullscreen oriented code... it should help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download