如何让js代码不可见? [英] How to make js code invisible?

查看:252
本文介绍了如何让js代码不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php页面,在页面底部我有一些javascript代码。



我在JavaScript代码中使用php,如下所示: p>

  alert(<?php echo $ variable;?>); 

如果我把它放在一个单独的文件中,这不会因为某种原因而起作用。
有没有办法使它从一个单独的文件工作,没有太多的困难?



或者有另一种方式我不知道还没有做出JavaScript代码对用户不可见? (例如,他们不能通过查看源代码看到代码)

谢谢

解决方案

Javascript由浏览器解释,因此浏览器需要查看代码。这意味着它也可以被用户访问。 您无法从用户隐藏JavaScript 。你可以做的是混淆它,使用户难以阅读代码。

I have a php page, where at the bottom of the page I have some javascript code.

I use php inside the javascript code, like this:

alert ("<?php echo $variable; ?>");

If I put this in a separate file, this wont work for some reason. Is there anyway to make it work from a separate file without too much difficulty?

Or is there another way I don't know of yet to make javascript code invisible for the users? (for example so they cant see the code by viewing the source code)

Thanks

解决方案

Javascript is interpreted by the browser, so the browser needs to see the code. This means that it is also accessible by the user. You cannot hide JavaScript from the user. What you can do is obfuscate it, to make it difficult for the user to read the code.

这篇关于如何让js代码不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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