The question is pretty much in the title. I want to return a value that tells me whether or not the element in question is in fullscreen. How do I do that using javascript? This seems to not work:
function fs_status()
{
var fullscreenElement = canvas.fullscreenElement ||canvas.mozFullscreenElement || canvas.webkitFullscreenElement;
return fullscreenElement;
}
//Sorry, I don't really understand js. So if your making an example can you please use 'canvas' as the element in question.
I found out how to do it after playing around a little:
function fs_status() {
if (document.fullscreenElement || document.webkitFullscreenElement ||
document.mozFullScreenElement)
return 1;
else
return -1;
}
Sadly, Fullscreen API still is a mess when you try to work on different browsers.
Webkit browsers and Firefox do include a isFullscreen
property to the document, but not IE. But, you can use a workaround looking for msFullscreenElement
which might be set to undefined
if no fullscreen was requested.
Here is kinda polyfill you can use :
if (typeof(document.isFullscreen === undefined)) {
document.isFullscreen = function() {
return document.webkitIsFullscreen || //Webkit browsers
document.mozFullScreen || // Firefox
document.msFullscreenElement !== undefined; // IE
};
}
Didn't tested it on IE but it should work.
Note : call it like that : if( document.isFullscreen() ){ fullscreenOn }else{ fullscreenOff }
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