Javascript 如何隐藏javascript代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2222355/
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 javascript code
提问by
Possible Duplicate:
How can I obfuscate JavaScript?
可能的重复:
如何混淆 JavaScript?
Hello!
你好!
Is it possible to hide JS code? How? I read somewhere a technique like: take JS to external file, and use js-encrypt.
是否可以隐藏 JS 代码?如何?我在某处读到了一种技术,例如:将 JS 带到外部文件,并使用 js-encrypt。
I know that is impossible to hide from all eyes, but...
我知道这不可能躲过所有人的眼睛,但是……
Thank you.
谢谢你。
回答by Dead account
It is not possible to hide Javascript from the user, since their browser needs to download it to execute it. The only other option is obfuscation.
不可能对用户隐藏 Javascript,因为他们的浏览器需要下载它才能执行它。唯一的其他选择是混淆。
回答by PeanutPower
You can run your private JavaScript server side e.g. using ASP JScript.NET
您可以运行您的私有 JavaScript 服务器端,例如使用 ASP JScript.NET
<% WebService Language="JScript" Class="MyClass" %>
You can put the hidden functionality on the server and call it via AJAX in the non hidden part of the code on the client.
您可以将隐藏的功能放在服务器上,并在客户端代码的非隐藏部分通过 AJAX 调用它。
you can also use
你也可以使用
<script runat="server">
or if you're not using a Microsoft platform you might consider Mozilla Rhino
或者如果您不使用 Microsoft 平台,您可能会考虑Mozilla Rhino
回答by Sarfraz
As you can take someone else's code and try to encrypt it, same goes for others who can take your code. The only solution that i think is to obfuscate your javascript code so that it becomes little difficult for others to grasp but there again there decryptors available so no real solution as of what i know has come about so far.
由于您可以获取其他人的代码并尝试对其进行加密,因此其他可以获取您代码的人也是如此。我认为唯一的解决方案是混淆你的 javascript 代码,这样其他人就不会很难掌握了,但同样有解密器可用,所以到目前为止我所知道的还没有真正的解决方案。
回答by rATRIJS
The simple answer is no - since the browser needs to understand the javascript, then the user will be able to understand the javascript...
简单的答案是否定的 - 由于浏览器需要理解 javascript,那么用户将能够理解 javascript...

