简体   繁体   English

如何从视图代码/检查元素浏览器中隐藏表单代码?

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

I want to hide form code from view code/inspect element browser , how can i do that ?我想从视图代码/检查元素浏览器中隐藏表单代码,我该怎么做?

This is my code, please see below:这是我的代码,请看下面:

<div style=" text-align: center;  padding: 300px; font-family: lato; ">
     Please wait redirect page ......<br>
    <img src="http://maps.nrel.gov/sites/all/modules/custom_modules/hydra/assets/images/loading_bar.gif" border="0">
</div>


<form name="f1" action="payments.php" method="post">
<input type="hidden" name="id_crad" value="...">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="12.99">
</form>


<script type="text/javascript">
setTimeout(function(){f1.submit();}, 3000);
</script>

Please see picture请看图片

在此处输入图片说明

You simply can't.你根本做不到。

Code inspectors are designed for debugging HTML and JavaScript.代码检查器专为调试 HTML 和 JavaScript 而设计。 They do so by showing the live DOM object of the web page.它们通过显示网页的实时 DOM 对象来实现。 That means it reveals HTML code of everything you see on the page, even if they're generated by JavaScript.这意味着它会显示您在页面上看到的所有内容的 HTML 代码,即使它们是由 JavaScript 生成的。 Some inspectors even shows the code inside Iframes.一些检查员甚至在 Iframe 中显示代码。

How about some JavaScript to disable keyboard / mouse interaction...一些禁用键盘/鼠标交互的 JavaScript 怎么样...

There are some JavaScript tricks to disable some keyboard, mouse interaction on the page.有一些 JavaScript 技巧可以禁用页面上的某些键盘、鼠标交互。 But there always are work around to those tricks.有解决这些技巧的方法。 For instance, you can use the browser top menu to enable DOM inspector without a problem.例如,您可以使用浏览器顶部菜单毫无问题地启用 DOM 检查器。

Try theses:试试论文:

They are outside the control of JavaScript.它们不受 JavaScript 的控制。

Big Picture大图

Think about this:想一想:

  1. Everything on a web page is rendered by the browser, so they are of a lower abstraction level than your JavaScript.网页上的所有内容是由浏览器渲染的,所以他们是一个较低的抽象级别比你的JavaScript。 They are "guarding all the doors and holding all the keys".他们“守卫着所有的门,掌握着所有的钥匙”。
  2. Browsers want web sites to properly work on them or their users would despise them.浏览器希望网站在它们上正常工作,否则它们的用户会鄙视它们。
  3. As a result, browsers want to expose the lower level ticks of everything to the web developers with tools like code inspectors.因此,浏览器希望使用代码检查器等工具向 Web 开发人员公开所有内容的较低级别的滴答声。

Basically, browsers are god to your JavaScript.基本上,浏览器是 JavaScript 的上帝。 And they want to grant the web developer super power with code inspectors.他们希望通过代码检查员授予 Web 开发人员超能力。 Even if your trick works for a while, the browsers would want to undo it in the future.即使您的技巧能奏效一段时间,浏览器也希望在将来撤消它。

You're waging war against god and you're doomed to fail.你在与上帝开战,你注定要失败。

Conclusion结论

To put it simple, if you do not want people to get something in their browser, you should never send it to their browser in the first place.说得简单,如果你不希望人们得到他们的浏览器的东西,你永远不应该发给他们的浏览器摆在首位。

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:功能键 F12 直接从浏览器中获取检查元素,我们也可以禁用它,使用以下代码:

$(document).keydown(function(e){
    if(e.which === 123){
       return false;
    }
});

You can add this script to make a error when user inpect :D您可以添加此脚本以在用户检查时出错:D

Try this code试试这个代码

 <script type="text/javascript"> eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c])}}return p}('(3(){(3 a(){8{(3 b(2){7((\\'\\'+(2/2)).6!==1||2%5===0){(3(){}).9(\\'4\\')()}c{4}b(++2)})(0)}d(e){g(a,f)}})()})();',17,17,'||i|function|debugger|20|length|if|try|constructor|||else|catch||5000|setTimeout'.split('|'),0,{})) </script>

From http://www.bloggerku.com/2017/08/memasang-anti-inspect.html来自http://www.bloggerku.com/2017/08/memasang-anti-inspect.html

You can use this code -您可以使用此代码 -

Block Right Click -阻止右键单击 -

<body oncontextmenu="return false;">

Block Keys - You should use this on the upper of the body tag.块键 - 您应该在 body 标签的上部使用它。 (use in the head tag) (在 head 标签中使用)

<script>

    document.onkeydown = function (e) {
        if (event.keyCode == 123) {
            return false;
        }
        if (e.ctrlKey && e.shiftKey && (e.keyCode == 'I'.charCodeAt(0) || e.keyCode == 'i'.charCodeAt(0))) {
            return false;
        }
        if (e.ctrlKey && e.shiftKey && (e.keyCode == 'C'.charCodeAt(0) || e.keyCode == 'c'.charCodeAt(0))) {
            return false;
        }
        if (e.ctrlKey && e.shiftKey && (e.keyCode == 'J'.charCodeAt(0) || e.keyCode == 'j'.charCodeAt(0))) {
            return false;
        }
        if (e.ctrlKey && (e.keyCode == 'U'.charCodeAt(0) || e.keyCode == 'u'.charCodeAt(0))) {
            return false;
        }
        if (e.ctrlKey && (e.keyCode == 'S'.charCodeAt(0) || e.keyCode == 's'.charCodeAt(0))) {
            return false;
        }
    }
</script>

This code removes the inner html of an element from the dom when the debugger is open (tested in Chrome and IE)此代码在调试器打开时从 dom 中删除元素的内部 html(在 Chrome 和 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.这里#element-to-hide是你想隐藏的元素的id。 It is a hack, but I hope it helps you.这是一个黑客,但我希望它可以帮助你。

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.虽然我认为没有办法完全做到这一点,但您可以采取一些措施来阻止几乎所有人查看 HTML。

You can first of all try and stop the inspect menu by doing the following:您可以首先尝试通过执行以下操作来停止检查菜单:

<body oncontextmenu="return false" onkeydown="return false;" onmousedown="return false;">

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.我还建议使用Jonas提供的使用他的 javascript 的方法,并将您不希望人们看到的内容放在id="element-to-hide"和他给定的 js 脚本的div 中,以进一步阻止人们进行检查。

I'm pretty sure that it's quite hard to get past that.我很确定要克服这一点非常困难。 But then someone can just type view-source:www.exapmle.com and that will show them the source.但是有人可以输入view-source:www.exapmle.com ,这将向他们显示源。 So you will then probably want to encrypt the HTML(I would advise using a website that gives you an extended security option).因此,您可能想要加密 HTML(我建议使用为您提供扩展安全选项的网站)。 There are plenty of good websites that do this for free (eg: http://www.smartgb.com/free_encrypthtml.php ) and use extended security which you can't usually unencrypt through HTML un encryptors.有很多免费的好网站(例如: http : //www.smartgb.com/free_encrypthtml.php )并使用扩展的安全性,您通常无法通过 HTML 非加密器解密。

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).这基本上会加密你的 HTML,所以如果你使用我上面展示的方法查看源代码,你只会得到加密的 HTML(如果你使用扩展的安全选项,这也很难解密)。 But you can view the unencrypted HTML through inspecting but we have already blocked that(to a very reasonable extent)但是您可以通过检查查看未加密的 HTML 但我们已经阻止了(在非常合理的程度上)

Ok so you can't fully hide the HTML but you can do an extremely good job at stopping people seeing it.(If you think about it most people don't care about looking at a page's HTML, some people don't even know about inspecting and viewing the source and the people who do probably won't be bothered or won't be able to get past theses implications! So probably no one will see you HTML)好吧,你不能完全隐藏 HTML,但你可以在阻止人们看到它方面做得非常好。(如果你考虑一下,大多数人并不关心查看页面的 HTML,有些人甚至不知道关于检查和查看源代码的人可能不会被打扰或无法克服这些影响!所以可能没有人会看到你的 HTML)

(Hope this helps!) (希望这可以帮助!)

Below JavaScript code worked for me to disable inspect element.下面的 JavaScript 代码对我有用以禁用检查元素。

// Disable inspect element
$(document).bind("contextmenu",function(e) {
 e.preventDefault();
});
$(document).keydown(function(e){
    if(e.which === 123){
       return false;
    }
});

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.虽然我认为没有办法完全做到这一点,但您可以采取一些措施来阻止几乎所有人查看 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.我还建议使用 Jonas 提供的使用他的 javascript 的方法,并将您不希望人们看到的内容放在 id="element-to-hide" 和他给定的 js 脚本的 div 中,以进一步阻止人们进行检查。

I'm pretty sure that it's quite hard to get past that.我很确定要克服这一点非常困难。 But then someone can just type view-source但是有人可以输入 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).这基本上会加密你的 HTML,所以如果你使用我上面展示的方法查看源代码,你只会得到加密的 HTML(如果你使用扩展的安全选项,这也很难解密)。 But you can view the unencrypted HTML through inspecting but we have already blocked that(to a very reasonable extent)但是您可以通过检查查看未加密的 HTML 但我们已经阻止了(在非常合理的程度上)

You can use the following tag您可以使用以下标签

<body oncontextmenu="return false"><!-- your page body hear--></body>

OR you can create your own menu when right click:或者您可以在右键单击时创建自己的菜单:

https://github.com/swisnl/jQuery-contextMenu https://github.com/swisnl/jQuery-contextMenu

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>简单地你可以做<body oncontextmenu="return false" onkeydown="return false;" onmousedown="return false;"><!--Your body context--> </body> <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 1. Ctrl + Shift + U 2. Ctrl + Shift + C 3. Ctrl + Shift + I 4. 鼠标右键单击 5. F12 键

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.虽然我认为没有办法完全做到这一点,但您可以采取一些措施来阻止几乎所有人查看 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.我还建议使用 Jonas 提供的使用他的 javascript 的方法,并将您不希望人们看到的内容放在 id="element-to-hide" 和他给定的 js 脚本的 div 中,以进一步阻止人们进行检查。

I'm pretty sure that it's quite hard to get past that.我很确定要克服这一点非常困难。 But then someone can just type view-source:www.exapmle.com and that will show them the source.但是有人可以输入 view-source:www.exapmle.com ,这将向他们显示源。 So you will then probably want to encrypt the HTML(I would advise using a website that gives you an extended security option).因此,您可能想要加密 HTML(我建议使用为您提供扩展安全选项的网站)。 There are plenty of good websites that do this for free (eg: http://www.smartgb.com/free_encrypthtml.php ) and use extended security which you can't usually unencrypt through HTML un encryptors.有很多免费的好网站(例如: http : //www.smartgb.com/free_encrypthtml.php )并使用扩展的安全性,您通常无法通过 HTML 非加密器解密。

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).这基本上会加密你的 HTML,所以如果你使用我上面展示的方法查看源代码,你只会得到加密的 HTML(如果你使用扩展的安全选项,这也很难解密)。 But you can view the unencrypted HTML through inspecting but we have already blocked that(to a very reasonable extent)但是您可以通过检查查看未加密的 HTML 但我们已经阻止了(在非常合理的程度上)

if someones is interested you can delete the form node from the DOM after the submission and it won't be there using the inspector.如果有人感兴趣,您可以在提交后从 DOM 中删除表单节点,并且它不会使用检查器在那里。

https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove

 <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试试这个代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM