如何使用jQuery告诉网站访问者之前是否访问过该网站?

时间:2009-04-16 14:42:43

标签: javascript jquery cookies

我想创建一个div容器,其中包含第一次访问我网站的消息。访问者将阅读它并单击“隐藏”按钮以永久消除它。

这是怎么做到的?

2 个答案:

答案 0 :(得分:8)

如何将Cookie plugin用于jQuery?

$.cookie('the_cookie', 'the_value'); // Create a session cookie ("the_cookie") and set its value to "the_value"
$.cookie('chocolate_chip_cookie', 'the_value', { // create a cookie with all available options
    expires: 7, // expires in seven days
    path: '/', // accessible from the whole site...
    domain: 'jquery.com',
    secure: true // ...but only on a secure connection
});
$.cookie('the_cookie', null); // delete the session cookie

答案 1 :(得分:0)

您可以通过以下方式完成此任务:

  1. 设置cookie。
  2. 在会话中存储状态。
  3. 您可以使用JavaScript,也可以使用PHP。 2.只能在服务器端完成,例如PHP。

    本教程可能会有所帮助: http://www.shopdev.co.uk/blog/cookies-with-jquery-designing-collapsible-layouts/

相关问题