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

前端 未结 13 2267
深忆病人
深忆病人 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: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.

提交回复
热议问题