How to hide form code from view code/inspect element browser?

前端 未结 13 2220
深忆病人
深忆病人 2020-11-29 01:15

I want to hide form code from view code/inspect element browser , how can i do that ?

This is my code, please see below:

相关标签:
13条回答
  • 2020-11-29 02:14

    While I don't think there is a way to fully do this you can take a few measures to stop almost everyone from viewing the HTML.

    You can first of all try and stop the inspect menu by doing the following:

    I would also suggest using the method that Jonas gave of using his javascript and putting what you don't want people to see in a div with id="element-to-hide" and his given js script to furthermore stop people from inspecting.

    I'm pretty sure that it's quite hard to get past that. But then someone can just type view-source

    This will basically encrypt your HTML so if you view the source using the method I showed above you will just get encrypted HTML(that is also extremely difficult to unencrypt if you used the extended security option). But you can view the unencrypted HTML through inspecting but we have already blocked that(to a very reasonable extent)

    0 讨论(0)
  • 2020-11-29 02:17

    Below JavaScript code worked for me to disable inspect element.

    // Disable inspect element
    $(document).bind("contextmenu",function(e) {
     e.preventDefault();
    });
    $(document).keydown(function(e){
        if(e.which === 123){
           return false;
        }
    });
    
    0 讨论(0)
  • 2020-11-29 02:17

    you can not stop user from seeing our code but you can avoid it by disabling some keys

    simply you can do <body oncontextmenu="return false" onkeydown="return false;" onmousedown="return false;"><!--Your body context--> </body>

    After doing this following keys get disabled automatically

    1. Ctrl + Shift + U 2. Ctrl + Shift + C 3. Ctrl + Shift + I 4. Right Click of mouse 5. F12 Key

    0 讨论(0)
  • 2020-11-29 02:18

    There is a smart way to disable inspect element in your website. Just add the following snippet inside script tag :

    $(document).bind("contextmenu",function(e) {
     e.preventDefault();
    });
    

    Please check out this blog

    The function key F12 which directly take inspect element from browser, we can also disable it, by using the following code:

    $(document).keydown(function(e){
        if(e.which === 123){
           return false;
        }
    });
    
    0 讨论(0)
  • 2020-11-29 02:18

    <script>
    document.onkeydown = function(e) {
    if(event.keyCode == 123) {
    return false;
    }
    if(e.ctrlKey && e.keyCode == 'E'.charCodeAt(0)){
    return false;
    }
    if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)){
    return false;
    }
    if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)){
    return false;
    }
    if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)){
    return false;
    }
    if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)){
    return false;
    }
    if(e.ctrlKey && e.keyCode == 'H'.charCodeAt(0)){
    return false;
    }
    if(e.ctrlKey && e.keyCode == 'A'.charCodeAt(0)){
    return false;
    }
    if(e.ctrlKey && e.keyCode == 'E'.charCodeAt(0)){
    return false;
    }
    }
    </script>

    Try this code

    0 讨论(0)
  • 2020-11-29 02:21

    This code removes the inner html of an element from the dom when the debugger is open (tested in Chrome and IE)

    var currentInnerHtml;
    var element = new Image();
    var elementWithHiddenContent = document.querySelector("#element-to-hide");
    var innerHtml = elementWithHiddenContent.innerHTML;
    
    element.__defineGetter__("id", function() {
        currentInnerHtml = "";
    });
    
    setInterval(function() {
        currentInnerHtml = innerHtml;
        console.log(element);
        console.clear();
        elementWithHiddenContent.innerHTML = currentInnerHtml;
    }, 1000);
    

    Here #element-to-hide is the id of element you want to hide. It is a hack, but I hope it helps you.

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