如何调用js而不显示代码
我想知道,我想在一些网站中植入一个JS跟踪代码(分析)来跟踪他们的流量。 但我不希望人们在查看网站的源代码时能够看到我在那里嵌入了 JS 跟踪代码。
是否可以? 也许通过使用 Apache/PHP 技巧?
谢谢,
罗伊。
I was wondering, I want to plant a JS tracking code (analytics) in a few websites to track their traffic. But I don't want that when viewing the site's source code people will be able to see that I've embedded the JS tracking code there.
Is it possible? Maybe by using an Apache/PHP trick?
Thanks,
Roy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,这是不可能的,对于浏览器执行任何代码来说,至少其中一些代码必须最初可见,即使该代码随后要检索跟踪代码本身。
此外,所有现代 Web 开发人员工具都提供对已加载的任何代码的访问,因此任何人都可以使用这些工具来查看您尝试单独加载的任何内容。
更重要的问题是你为什么要隐藏你正在跟踪的人?
Nope it's not possible, for the browser to execute any code at least some of it must be initially visible, even if that code is to then retrieve the tracking code itself.
In addition all the modern web developer tools provide access to any code that is loaded so anyone can use those to see anything you've attempted to load discretely.
The more important question is why you want to hide that you're tracking people?
这对于 Javascript 来说并不是绝对可能的。 Javascript 始终在用户浏览器的上下文中运行,因此它始终意味着用户有权查看脚本。 你可以对其进行混淆,或者在 JS 代码上尝试一些类似于反盗链的技巧,但对于某人来说,使用 Firebug 这样的简单工具来弄清楚代码的作用仍然相对容易。
不过,您可以在没有 JavaScript 的情况下跟踪您的流量。 Analytics 使用 JavaScript 来实现可移植性,因为它访问的某些数据只能通过 JavaScript 访问。 但是,还有一些不需要 JavaScript 的更被动的流量跟踪方法,例如任何日志分析器< /a> 类似于 AWstats。 您只是无法获得 Analytics 的一些很酷的功能。
It's not absolutely possible with Javascript. Javascript always runs in the context of the user's browser, so it always means that the user will have access to see the script. You can obfuscate it, or try some tricks similar to anti-hotlinking on the JS code, but it will still be relatively easy for someone to figure out what the code does with a simple tool like Firebug.
You can, however, track your traffic without JavaScript. Analytics uses JavaScript for portability, and because some of the data it accesses can only be accessed with JavaScript. However, there are more passive ways of tracking your traffic which don't require JavaScript, such as any log analyzer like AWstats. You just don't get some of the cool features of Analytics.
这是不可能的,但您可以将脚本文件命名为无害的名称,例如“mouseover.js”。
It's not possible, but you could just name your script file something innocent like "mouseover.js".
这是不可能的:JS 代码必须由 Web 浏览器运行,这意味着 - 无论您尝试以哪种方式放置它 - 它都必须能够被浏览器读取,从而能够被检查页面的任何人读取。
您可以尝试混淆 JS,但这不会阻止任何决心了解正在发生的事情的人。
您可以问自己,有多少人会检查您是否在跟踪他们——我没想到会这样。
It's not possible: JS code has to be run by the web browser, which means that -- which ever way you try put it -- it has to be readable by the browser and thus by anyone that inspects the page.
You could try obfuscating the JS, but that won't stop anyone that is determined to see what's happening.
You could ask yourself what the odds are that more than a few people will check whether you're tracking them -- I wouldn't expect it.
从技术上讲,您无法隐藏代码...但您可以对其进行打乱,这样任何人都无法读取它。 我使用 Dan Benjamin 的 http://hivelogic.com/enkoder/form 在我的页面(在这种情况下,我打乱了我的电子邮件地址)。 它对它进行打乱,以便浏览器可以执行它,但它不是人类可读的...
然后你可以将它作为函数调用,就像我在这个脚本中所做的那样 http://www.jamischarles.com/css_js/email_encoder.js。 试一试。
You can't technically hide the code... But you can scramble it so it's not readable to anybody. I used http://hivelogic.com/enkoder/form by Dan Benjamin to scrable some JS on my page (in this case I scrambled my email address). It scrambles it so the browser can execute it, but it's not humanly readable...
Then you can just call it as a function like I did in from this script http://www.jamischarles.com/css_js/email_encoder.js. Give it a try.