欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JavaScript 利用监听实现右键检查就 Debugger

程序员文章站 2022-07-02 19:27:56
文件上传
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传</title>
</head>
<body>
    <form action="http://localhost:8080/upload" method="POST">
        <p>
            上传人: <input type="text" name="username" />
        </p>
        
        <p>
            文件1: <input type="file" name="file1" />
        </p>
        
        <p>
            文件2: <input type="file" name="file2" />
        </p>

        <input type="submit" /> | <input type="reset" />
    </form>

    <h2>右键检查试试</h2>

    <script>
        var check = (function () {
            var callbacks = [], timeLimit = 2, open = false;
            setInterval(loop, 2);
            return {
                addListener: function (fn) {
                    callbacks.push(fn);
                },
                cancleListenr: function (fn) {
                    callbacks = callbacks.filter(function (v) {
                        return v !== fn;
                    });
                }
            }
            function loop() {
                var startTime = new Date();
                debugger;

                if (new Date() - startTime > timeLimit) {
                    if (!open) {
                        callbacks.forEach(function (fn) {
                            fn.call(null);
                        });
                    }
                    open = true;
                } else {
                    open = false;
                }
            }
        })();

        check.addListener(function () {
            //alert('Open Devtool');
        });
    </script>
</body>
</html>

本文地址:https://blog.csdn.net/weixin_44953227/article/details/112576352

相关标签: JavaScript