The problem is that the API hooks for request and cancel full screen are different; it is not a toggle on it's own.
You need to make some minor modifications:
var fullScreen = false;
function toggleFullScreen() {
if (element.requestFullScreen) {
if(fullScreen){
element.CancelFullScreen();
fullScreen = false;}
else{
element.requestFullScreen();
fullScreen = true;
}
} else if (element.webkitRequestFullScreen) {
if(fullScreen){
element.webkitCancelFullScreen();
fullScreen = false;
}
else{
element.webkitRequestFullScreen();
fullScreen = true;
}
} else if (element.mozRequestFullScreen) {
if(fullScreen){
element.mozCancelFullScreen();
fulLscreen = false;
}
else{
element.mozRequestFullScreen();
fullScreen = true;
}
}
}
For more information:
https://developer.mozilla.org/en-US/docs/Web/API/Document/mozCancelFullScreen[
^]