Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExitFullScreen not working + anyway to keyboard press on button click?

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?

like image 208
Friedpanseller Avatar asked Dec 12 '22 06:12

Friedpanseller


1 Answers

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

like image 76
code-jaff Avatar answered Dec 13 '22 20:12

code-jaff