如何从“检查元素”和“查看源”选项中隐藏 HTML 和 Javascript 代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27056990/
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
How to hide HTML and Javascript codes from Inspect Element and View source options?
提问by raja beta
I've made my web application and did hardwork to make this almost lost 180 days to make this. All my application is made into JAvascript. But i could see, many smart persons still can steal my codes. Can you please help me? How to encrypt in such a way that my code will never show into Inspect element and View Source? Is there any Algorithm?
我已经制作了我的 Web 应用程序并努力工作,使这几乎失去了 180 天来制作它。我所有的应用程序都被制作成 JAvascript。但是我可以看到,许多聪明人仍然可以窃取我的代码。你能帮我么?如何以我的代码永远不会显示到 Inspect 元素和 View Source 中的方式进行加密?有算法吗?
Here is my code When i see into inspect Element and View Source:
这是我的代码,当我查看检查元素和查看源代码时:
<!DOCTYPE html>
<html lang="en" class="app">
<head>
<meta charset="utf-8" />
<meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="stylesheet" href="js/jplayer.flat.css" type="text/css" />
<link rel="stylesheet" href="css/app.v1.css" type="text/css" />
<link rel="stylesheet" href="css/load_bar.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/load_bar.js"></script>
<script src="js/app.v1.js"></script>
<script src="js/app.plugin.js"></script>
<script type="text/javascript" src="js/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="js/jplayer.playlist.min.js"></script>
<script type="text/javascript" src="js/music_list.js">
</script>
--------
--------
--------
<!--[if lt IE 9]> <script src="js/ie/html5shiv.js"></script> <script src="js/ie/respond.min.js"></script> <script src="js/ie/excanvas.js"></script> <![endif]-->
</head>
<body class="some-content-related-div" id="inner-content-div">
<section class="vbox">
PLEASE HELP, How to Encrypt it?
请帮助,如何加密它?
HELP WOULD BE APPRECIATED!
帮助将不胜感激!
回答by Hujjat Nazari
The Javascript code is executed in the browser, i.e. on the client side, which means it must be available not-encrypted on the client side.
Javascript 代码在浏览器中执行,即在客户端,这意味着它必须在客户端未加密时可用。
The "best" you can do is probably to minify it, which will make it harder to understand it -- and a bit of obfuscationmight do too -- even if someone really motivated will still be able to read it.
您可以做的“最好”可能是缩小它,这会使它更难理解——而且 可能会做一些混淆——即使有人真的有动力仍然能够阅读它。
See for instance the YUI Compressor, which can both minify and obfuscate JS code.
参见例如YUI Compressor,它可以缩小和混淆 JS 代码。
回答by Laura
Simple answer: You can't.
简单的回答:你不能。
The only thing you can do is to uglify everything so it's not easy to read anymore, but anything that is sent to the browser is also theoretically visible to the user.
您唯一能做的就是丑化所有内容,这样就不再容易阅读了,但是发送到浏览器的任何内容理论上对用户也是可见的。
回答by mahip_j
It is not possible but you can minify it using many compressors which are available online.
这是不可能的,但您可以使用许多在线可用的压缩器来缩小它。
回答by Pratyush Harichandan
You can surely do this. You can disable the inspect element functionality by adding the code snippet below :-
你肯定可以做到这一点。您可以通过添加以下代码片段来禁用检查元素功能:-
$(document).bind("contextmenu",function(e) {
e.preventDefault();
});
$(document).keydown(function(e){
if(e.which === 123){
return false;
}
});