Disable keyboard when using fullscreen mode

问题: 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>
  • 发表于 2019-03-28 10:16
  • 阅读 ( 178 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除