Full screen web API's allow to full screen element object. But full screen can be disabled using "Esc" key. I tried using event prevent Default method when "Esc" key is pressed. Even then full screen is disabled. I want my webpage to run in full screen mode, since it is online exam application, I don't want users to exit full screen and open new tabs and other applications.
Here is sample of code:
function openAppInFullScreen() {
let
rootEl = window.document.documentElement,
rfs = rootEl.requestFullScreen
|| rootEl.msRequestFullscreen
|| rootEl.webkitRequestFullScreen
|| rootEl.mozRequestFullScreen;
rfs.call(rootEl);
}
function disableOutofAppActions(event) {
let
isF5orF11key = (event.keyCode === 116 || event.keyCode === 122),
isCtrlKeyOrEsc = event.ctrlKey || (event.keyCode === 27);
if (isF5orF11key || isCtrlKeyOrEsc) {
/* Block the event */
event.preventDefault()
/*Show an warning alert*/
}
}
window.addEventListener("click", openAppInFullScreen);
window.addEventListener("keydown", disableOutofAppActions)