开发者

Jquery cookies (persisting cookies) with rails

开发者 https://www.devze.com 2023-04-02 04:59 出处:网络
I am using the jquery fromhttps://github.com/carhartl/jquery-cookie. I am using the cookies for very first time. If I set the query by:

I am using the jquery from https://github.com/carhartl/jquery-cookie. I am using the cookies for very first time. If I set the query by:

$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); 

This creates the query but do not retain after the browser is closed. I dont have idea how to do that.

Secondly, every time I refresh the page it over writes the cookies as I dont need like this, I need to have check whether I am t开发者_运维技巧he first visitor or no. If no get the cookied or else set the cookie.


You need to add a condition to see if a cookie already exists so that it doesn't get replaced. Try:

<script type="text/javascript">
$(function () {
  if($.cookie("new_visitor") != "true") {
    $.cookie("new_visitor", "true", { expires: 21, path: '/' });
    $.jGrowl("Hello Joe Public<br/><br/><a href='#'>Click me</a>", {sticky: true});
    }
  });
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消