使用javascript和Cookie计算网页访问次数 [英] Counting page visits with javascript and cookies

查看:431
本文介绍了使用javascript和Cookie计算网页访问次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算用户访问会话中的网站,并根据用户访问过的网页实施某些功能。我想只使用JavaScript和cookies(使用js)执行此操作。

I would like to count a users visit to a site within a session and implement certain functionality based on how many pages the user has visited. I would like to perform this solely with the use of JavaScript and cookies (using js).

基本上我只想创建 var = 0 ++ 到每次额外访问该用户会话中的另一个页面时的相同var。

Essentially I would just like to do create var = 0 and ++ to that same var on each additional visit to another page within that users session.

这是什么正确的方法?

推荐答案

例如,当用户访问页面时,首先检查cookie是否存在,如果不存在,则设置cookie名称和值,同时设置一个(令牌变量var)作为设置,以使页面刷新时增加。

You could for example, when the user access the page, First check if the cookie exists, if not then set the cookie name and value and also a (token var) as being set so it dosnt increment on page refreshes.

然后每隔一个页面你需要cookie,再次检查cookie,然后增加它。

Then one every other page you require the cookie, again check for cookie and then increment it.

我发现一个易于使用coolkie脚本 Cookie 使用。

I find a easy to use coolkie script Cookies use.

这篇关于使用javascript和Cookie计算网页访问次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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