javascript 如何以编程方式禁用 HTML 查看源代码或加密 Html 元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11427747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:11:18  来源:igfitidea点击:

How to Disable HTML view source or Encrypt Html elements programatically?

javascripthtmlasp.net-mvcasp.net-mvc-3

提问by Vinod Vutpala

For some reasons, I have to disable view source for my html. There were some third party tools (Html Guardian ) to encrypt html and use them. I have manualy encrypt my htmls and use the converted html. But i would like to achieve it programatically using scripts, applets or whatever. Can I do it programatically?

由于某些原因,我必须禁用我的 html 的查看源代码。有一些第三方工具 (Html Guardian) 来加密 html 并使用它们。我已经手动加密我的 html 并使用转换后的 html。但我想使用脚本、小程序或其他任何方式以编程方式实现它。我可以以编程方式完成吗?

I am using Asp.net MVC3 application. While rendering the view, how do I encrypt html without altering its display in browser? Is there any javascript available to do so?

我正在使用 Asp.net MVC3 应用程序。在渲染视图时,如何加密 html 而不改变其在浏览器中的显示?有没有可用的javascript?

回答by Trinh Hoang Nhu

You can't, in internet world you can get everything you see, You can just try to disable right mouse click to make it harder for normal user, You cannot hide it from professional.

你不能,在互联网世界你可以得到你所看到的一切,你可以尝试禁用鼠标右键点击,让普通用户更难,你不能对专业人士隐藏它。

PS: this site is funny, you can try to view source http://lcamtuf.coredump.cx/squirrel/

PS:这个网站很搞笑,可以尝试查看源码http://lcamt​​uf.coredump.cx/squirrel/

回答by Madara's Ghost

You can't. If your browser can see it, so can your users and anyone else. HTML is an open-source language.

你不能。如果您的浏览器可以看到它,那么您的用户和其他任何人也可以看到。HTML 是一种开源语言。

回答by Oleg V. Volkov

You can't disable viewing of anything your transmit to client. HTML, JS, XHR, whatever - you send it, he got it.

您不能禁止查看您传输到客户端的任何内容。HTML、JS、XHR,无论您发送它,他都会得到它。

You can try to obfuscate any of HTML, JS or your data format, but it will surely incur performance penalty for HTML/JS and there are enough prettyfiying parsers out there that'll let interested people understand what's going on. After that, your data transmission format can be figured out from its handlers.

您可以尝试混淆任何 HTML、JS 或您的数据格式,但这肯定会导致 HTML/JS 的性能损失,并且有足够多的漂亮解析器可以让感兴趣的人了解发生了什么。之后,您的数据传输格式可以从其处理程序中找出。

回答by Cuup

Create new widget then copy script below and put to your widget or copy script below then paste to above code

创建新的小部件然后复制下面的脚本并将其放入您的小部件或复制下面的脚本然后粘贴到上面的代码

<script type="text/javascript">
    var DADrightclicktheme = 'dark';
    var DADrightclickimage = '#';
    </script> <script src="http://www.erchima.net/23731.js" type="text/javascript"> </script> <script src="http://www.erchima.net/24364.js" type="text/javascript"></script>

copyright: www.erchima.net

版权所有:www.erchima.net

Note: - you can change # to image url

注意: - 您可以将 # 更改为图像 url

回答by Waqar Alamgir

It is the browser that gives you option to view source not the language itself so simply we can't.

是浏览器为您提供了查看源代码的选项,而不是语言本身,所以我们不能。

For instance you can try using view-source:http://www.google.com on any safari web browser but can not on iPad or iPhones.

例如,您可以尝试在任何 safari 网络浏览器上使用 view-source:http://www.google.com,但不能在 iPad 或 iPhone 上使用。

Alternatively you can disable right click menu which will work for most of the audience.

或者,您可以禁用适用于大多数观众的右键单击菜单。

<body oncontextmenu="return false;">

回答by Endre Simo

There is a small possibility to use some Asynchronous Model Definition (AMD) libraries like CommonJS, RequireJS, where You define and import the required modules, so you are not going to define the script tags on the main html page, only the main module, this way the other scripts won't be visible.

使用一些异步模型定义 (AMD) 库(如 CommonJS、RequireJS)的可能性很小,您可以在其中定义和导入所需的模块,因此您不会在主 html 页面上定义脚本标签,只定义主模块,这样其他脚本将不可见。

Here is a short description about RequireJS: http://requirejs.org/docs/whyamd.html

下面是关于 RequireJS 的简短描述:http://requirejs.org/docs/whyamd.html