how to disable right click, f12(debug) and ctrl+s in asp.net application using javascript or jquery

前端 未结 4 1222
抹茶落季
抹茶落季 2021-01-29 12:42

how to disable right click, f12(debug) and ctrl+s in asp.net application using javascript or jquery.. Have to black ctrl+s --> Do not allow to save the page Have to black f12

相关标签:
4条回答
  • 2021-01-29 13:17
    <script type="text/javascript">
    if (document.layers) {
    //Capture the MouseDown event.
                        document.captureEvents(Event.MOUSEDOWN);
    
                        //Disable the OnMouseDown event handler.
                        document.onmousedown = function () {
                            return false;
                        };
                    }
                    else {
                        //Disable the OnMouseUp event handler.
                        document.onmouseup = function (e) {
                            if (e != null && e.type == "mouseup") {
                                //Check the Mouse Button which is clicked.
                                if (e.which == 2 || e.which == 3) {
                                    //If the Button is middle or right then disable.
                                    return false;
                                }
                            }
                        };
                    }
    
                    //Disable the Context Menu event.
                    document.oncontextmenu = function () {
                        return false;
                    };
                    document.onkeydown = ShowKeyCode;
                    function ShowKeyCode(evt) {
                        if (evt.keyCode == '123')
                            return false;
                         //For F12 Button 
                    }
    </script>
    
    0 讨论(0)
  • 2021-01-29 13:23

    There are some legitimate reasons for this functionality. We are doing web-based testing in a school district and we have to provide a reasonable assurance that students will not be able to find the source file of a test and download it or email it to themselves during the test. For that reason we have to disable right click and do everything we can to ensure that F12 and Ctrl U does not work. School districts with minimal budgets have no choice but to rely on these tricks to help get more done with less.

    0 讨论(0)
  • 2021-01-29 13:30

    Forget about it! I can write my own web browser which doesn't have right click, F12 and CTRL+S and I can still see the HTML and Javascript source. I can even do this with telnet.
    If your manager gave you such requirements I would tell him to go back to primary school.
    I know you can't tell him this. But really:
    You can't rely on the fact that some user agents will respect your tricks.
    This won't improve security - this will give you nothing.

    Just some background information:
    Some time ago I've written a script for Selenium WebDriver to control Firefox. I was able to grab any data, read all the scripts and moreover inject my own JS to any website.
    You should listen to the comments and answers and provide security on the server side because everything your server sends as a response can be read, saved and processed one way or another.

    0 讨论(0)
  • 2021-01-29 13:35

    "Do not allow to save the page" - This is impossible, as this would require not delivering the page to the user in the first place.

    "Do not allow to inspect/debug/view source of the page" - This is also impossible. In Chrome you can prepend view-source: to the URL, and you can get to developer tools with Menu -> Tools -> Developer Tools. In any case, the browser has to have access to the source code to actually display the page.

    What you are trying to do is impossible. There is also absolutely no reason to. (It's also highly annoying to legitimate users who actually want to right click!) If you're trying to do this for "security," this is most definitely not your biggest problem. If there's any insecure information delivered to client side, you have to redesign your entire system immediately.

    0 讨论(0)
提交回复
热议问题