Is it possible to disable esc/F11 key during full screen mode of webpage, programmatically? [duplicate]

Is it possible to disable esc/F11 key during full screen mode of webpage, programmatically? I need to have an exit button within the webpage to exit from fullscreen mode, but need to prevent to come outside the fullscreen mode using other funcationality of windows(like esc, F11, etc.). Please help me if anyone have any idea about this.

Answers:

Answer

With jQuery you can disable it listening to the keydown event:

$(document).on("keydown",function(ev){
	console.log(ev.keyCode);
	if(ev.keyCode===27||ev.keyCode===122) return false
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

keycode 27 stands for the ESC key and 122 for the F11. This was tested in chrome, maybe for other browsers can be other number

Answer
document.addEventListener("keydown", e => {
    if(e.key == "F11") e.preventDefault();
});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.