简体   繁体   English

网站进度存储?

[英]Website progress storage?

I'm pretty new to web development and have for most of you trivial question.Where and how to store website progress user did? 我是Web开发的新手,对于大多数人来说,这都是一个琐碎的问题。用户在哪里以及如何存储网站进度? I mean...for example.We have javascript variable 我的意思是...例如。我们有javascript变量

var a=0;

and

<div id="clickhere" onClick="a=a+1;document.getElementById('clickhere').innerHTML=a">

.Imagine someone clicked on that division once and leaves website.I want him to see displayed number one in that div after returning to website. 假设某人单击该部门一次并离开了网站。我希望他返回网站后在该div中看到显示的第一名。

You either need a server side to store this data, identify the client by some uid or login and retrive the data on repeated visit. 您或者需要服务器端来存储此数据,通过某些uid来标识客户端,或者登录并在重复访问时检索数据。 or a simpler solution, use a client side cookie. 或更简单的解决方案,请使用客户端Cookie。

If you only want visit data viewable to each individual user, you can use a local storage mechanism. 如果只希望访问数据对每个用户可见,则可以使用本地存储机制。 For clients whose browsers support HTML 5 you can use localstorage to store a retrieve the variable between user visits. 对于其浏览器支持HTML 5的客户端,您可以使用localstorage存储在用户访问之间的检索变量。 You could get he JavaScript to set a cookie and then check if a cookie exists per user visit, if it does, increment the visit count. 您可以使用JavaScript设置cookie,然后检查每次用户访问是否存在cookie,如果存在,则增加访问次数。

A more robust solution would be to persist the visit count server side. 一个更可靠的解决方案是保留访问计数服务器端。 You can issue a cookie to a user, on each future visit, you can either send the visit data to the server via Ajax, or by form submit. 您可以向用户发出cookie,在以后的每次访问中,您都可以通过Ajax将访问数据发送到服务器,也可以通过表单提交。 This would then need to be persisted to a database using a server side language such as php, ruby or .net. 然后,需要使用服务器端语言(例如php,ruby或.net)将其持久化到数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM