I am using the HTML5 Full-Screen API and including some content in the page. I don't want to close the full screen mode on any key clicks like ESC. Or I want to load the page again on ESC. And I tried capturing the ESC by the following code,
But When I do pressing ESC when full screen mode is active, the following function is not working. How can I disable ESC on full screen mode or do something on keydown the ESC?
$(document).ready(function (){
$(document).keydown(function(e){
var charCode = e.charCode || e.keyCode || e.which;
if (charCode == 27){
alert("Escape is not allowed!");
activateFullScreen(document.getElementById("myDiv"));
}
});
});
function activateFullScreen(element) {
if(element.requestFullScreen) {
element.requestFullScreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
function myFunction() {
activateFullScreen(document.getElementById("myDiv"));
}
html:
<body>
<button onclick="myFunction()">Try it</button>
<div id="myDiv"> Some content here </div>
</body>