Javascript点击网站的计数器 [英] Javascript hit counter for a website
问题描述
我正在尝试为网站编写点击计数器。作为首选项,不是必需的,我正在尝试使用Javascript来执行此操作。在网站的html文件中,我正在从javascript文件中读取一个数字并输出它。如果每次发生命中,我怎样才能使它计数?
I'm trying to code a hit counter for a website. As a preference, not required, I'm trying to use Javascript to do this. On the website's html file, I'm reading a number from a javascript file and outputting that. How can I make it "count" every time a hit occurs?
对于这样一个模糊的问题,我们深表歉意。我正走在正确的轨道上吗?任何提示,代码或参考将不胜感激。
Sorry for such a vague question. Am I on the right track going about this? Any tips, code, or references will be much appreciated.
谢谢!
推荐答案
使用Javascript,您只能计算当前用户的点击次数,因为您必须将计数保存在Cookie或客户端技术中。
Using Javascript you can only count the hits from the current user, because you have to save the count in a cookie or a client side technology.
更准确的方法你必须使用服务器端语言,并可能添加一个像数据库一样的存储引擎使其工作。
For a more accurate way you have to use a server-side language and maybe add a storage engine like a database to make it work.
我建议你从这里开始 Php适合初学者链接可能已经过时但它涵盖了所有内容创建计数器时需要了解的基础知识。
I suggest you start here Php for beginners the link might be old but it covers all the basics you need to know to create your counter.
这篇关于Javascript点击网站的计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!