undefined
is a falsey value, meaning the ||
operator will convert will consider it the same as false
.
If you just want to find the first value which is not defined you could try something like this:
var IFS =
(typeof document.isFullScreen != "undefined") ? document.isFullScreen :
(typeof document.webkitIsFullScreen != "undefined") ? document.webkitIsFullScreen :
(typeof document.mozIsFullScreen != "undefined") ? document.mozIsFullScreen :
(typeof document.msIsFullScreen != "undefined") ? document.msIsFullScreen :
false;
Or as Niet suggests:
var IFS =
('isFullScreen' in document) ? document.isFullScreen :
('webkitIsFullScreen' in document) ? document.webkitIsFullScreen :
('mozIsFullScreen' in document) ? document.mozIsFullScreen :
('msIsFullScreen' in document) ? document.msIsFullScreen :
false;
Or you could use an array, like this:
var arr = ['isFullScreen', 'webkitIsFullScreen', 'mozIsFullScreen', 'msIsFullScreen'];
var IFS = false;
for (var i = 0; i < arr.length; i++) {
if (arr[i] in document) {
IFS = document[arr[i]];
break;
}
}
Or like this
var arr = ['isFullScreen', 'webkitIsFullScreen', 'mozIsFullScreen', 'msIsFullScreen'];
var key = arr.filter(function(e) { return e in document; })[0];
var IFS = !!document[key];