Simple implementation of JS forbidding to view web source code

Keywords: Javascript

In project development, we sometimes encounter the source code information of the website that we don't want others to easily view. We have many ways to lightly protect our own website source code. Here are three ways to use JavaScript to protect your website source code:

The most common way to check the source code of a website is to have these four kinds:

1.F12
2. Right click
3.Ctrl+Shift+I
4.Ctrl+U
The above three methods can view the source code of the website. We can use JavaScript to block these three states to achieve the effect of forbidding viewing the source code. Put the source code directly below.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JS A simple way to disable viewing the source code of web page</title>
</head>
<body>
    <script type="text/javascript">
        window.onload = function(){
            //Block keyboard events
            document.onkeydown = function (){
                var e = window.event || arguments[0];
                //F12
                if(e.keyCode == 123){
                    return false;
                //Ctrl+Shift+I
                }else if((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)){
                    return false;
                //Shift+F10
                }else if((e.shiftKey) && (e.keyCode == 121)){
                    return false;
                //Ctrl+U
                }else if((e.ctrlKey) && (e.keyCode == 85)){
                    return false;
                }
            };
            //Mask right mouse button
            document.oncontextmenu = function (){
                return false;
            }
        }

    </script>
</body>
</html>

It's impossible to realize the pure. html of source code shielding. There's no way to stop it if you want to see the source code. This script can only prevent the little white gained without any effort. It can't work for the old computer and the big God. And now many browsers have the function of viewing the source code of the web page. You can download any file with the TELEPROT website download tool, which is equivalent to a mirror website. Want to really protect the source code, unless the server security settings, encryption.

Thanks for sharing: http://www.cnblogs.com/hollow/articles/6380660.html

Posted by 9999 on Tue, 07 Jan 2020 02:29:30 -0800