Skip to content

Instantly share code, notes, and snippets.

@georgebyte
Last active August 30, 2019 09:30
Show Gist options
  • Save georgebyte/3b915dd6b11a2660c096 to your computer and use it in GitHub Desktop.
Save georgebyte/3b915dd6b11a2660c096 to your computer and use it in GitHub Desktop.
Javascript: Toggle browser fullscreen mode
$('body').click(function(event) {
var el, rfs;
if ($('body').hasClass('fullscreen')) {
el = document;
rfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen;
$('body').removeClass('fullscreen');
} else {
el = document.documentElement;
rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen;
$('body').addClass('fullscreen');
}
if ('undefined' !== typeof rfs && rfs) {
var a = rfs.call(el);
} else if ('undefined' !== typeof window.ActiveXObject) {
var wscript = new ActiveXObject('WScript.Shell');
if (null !== wscript) {
wscript.SendKeys('{F11}');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment