如何在JavaScript中隐藏变量值? [英] How do I hide a variable value in JavaScript?

查看:305
本文介绍了如何在JavaScript中隐藏变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究JavaScript项目,并且知道可以通过浏览器访问JavaScript源代码.在代码中,我有一个变量,用于存储程序使用的秘密字符串.但是,我不希望其他人查看源代码并找出此变量的值. 是否可以隐藏变量的值?还是可以在之后更改变量的值?例如,更改实际源代码以将变量设置为其他值?此变量仅在第一次加载图像时使用,因此可以将其完全删除.

I am currently working on a JavaScript project and know that JavaScript source code is accessible through the browser. In the code, I have a variable that stores a secret string that is used by the program. However, I do not want others to view the source code and find out the value of this variable. Is there a way to hide the value of a variable? Or is it possible to change the variable value after? For instance, change the actual source code to set the variable to a different value? This variable is only used the first time an image is loaded so it would be okay to remove it altogether if that is possible.

推荐答案

您无法向程序员隐藏JavaScript内容.他们可以随时打开开发人员控制台并获取所有变量.

You cannot hide JavaScript content from a programmer. They can always open the developer console and get all your variables.

更糟糕的是,他们可以使用上述控制台直接绕过任何JavaScript验证,因此它不能成为您的主要安全性.

What's worse, they can use said console to directly bypass any JavaScript validation, so it cannot be your primary security.

如果必须隐藏或保护它,则必须研究服务器端解决方案.

If it is something you must hide or secure against, you must look into a server side solution.

这篇关于如何在JavaScript中隐藏变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆