问题:
I'm following this method for disable keyboard events. But this only works for inputs form. I just want when fullscreen mode is actived user cannot use keyboard. this is my...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
I'm following this method for disable keyboard events. But this only works for inputs form. I just want when fullscreen mode is actived user cannot use keyboard. this is my snipet codepen.io/adityadees/pen/Jzqmpy
document.onkeydown = function (e) {
return false;
}
<body onload="document.documentElement.webkitRequestFullScreen();">
<h1>Lock</h1>
<textarea></textarea>
</body>
回答1:
F11 and ESC will work
<html>
<head>
<title>Page Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$(document).keydown(function (event) {
return false;
});
});
document.oncontextmenu = function (e) //check for the right click
{
return false;
}
document.ondragstart = function (e)
{
return false;
}
function toggleFullScreen() {
var docElm = document.documentElement;
if ((document.fullScreenElement && document.fullScreenElement !== null) || (!document.mozFullScreen && !document.webkitIsFullScreen)) {
if (docElm.requestFullscreen) {
docElm.requestFullscreen();
}
else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen();
}
else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen();
}
}
else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
}
else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}
</script>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<input type=text id="text"/>
<button onclick="toggleFullScreen()" value="toggleFullScreen" name="toggleFullScreen">toggleFullScreen</button>
</body>
</html>