ThemeForest

About Browser's Cookie

1203 posts
  • Has been a member for 3-4 years
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a File in an Envato Bundle
  • Envato Staff
  • Reviewer
  • Lead Reviewer
  • Author had a Free File of the Month
  • Beta Tester
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Malaysia
  • Referred between 200 and 499 users
kailoon says

I am a little confused about this request, from my client.

They want a welcome box with cookie, user close it and it will not see it again in the next 24 hours. Pretty standard.

However, they request to have an option to change the welcome message and, to be able to reset the cookie as soon as they changed the message.

Does that mean, if the user visit the site and close the box (cookie expiry set to 1 day). Then the admin change the message, reset the cookie. Then the user return to the site in 2 hours and the user will see the box again? And, is that possible?

Any jquery or php expert can help?

5 months ago
kailoon is an Envato staff member
1205 posts
  • Has been a member for 2-3 years
  • Community Superstar
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Austria
  • Referred between 200 and 499 users
revaxarts says

You may use a cookie with a timestamp

showmessage = getCookie('alertbox_12_12_2011');
if(!showmessage){
   //show the message
}
onclosemessage = function(){
    //close box here
   setCookie('alertbox_12_12_2011',1,1);
}

Hope you get the idea.

You can use this getCookie and setCookie function

5 months ago
623 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Serbia
  • Referred between 1 and 9 users
rvision_ says
revaxarts said
You may use a cookie with a timestamp
showmessage = getCookie('alertbox_12_12_2011');
if(!showmessage){
   //show the message
}
onclosemessage = function(){
    //close box here
   setCookie('alertbox_12_12_2011',1,1);
}

Hope you get the idea.

You can use this getCookie and setCookie function

+1

You need some hash system to diferentiate cookies for each message. This one won’t work if there are more than 1 message per day, but you get the idea I hope :)

Also, it will be good to keep a list of messages somewhere and delete cookies which are not used anymore. Better solution will be to use JSON and pack all the data in 1 cookie and display only the latest message or something similar.

5 months ago
135 posts
  • Has been a member for 1-2 years
  • Won a Competition
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Europe
  • Referred between 200 and 499 users
pixelentity says

there’s no need to store multiple values/cookies, just use one and save timestamp of last message edit.

hide the box if cookie exists and saved timestamp == message, show it and set the cookie if not.

crc32 of message content would also work.

BF

5 months ago
1205 posts
  • Has been a member for 2-3 years
  • Community Superstar
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Austria
  • Referred between 200 and 499 users
revaxarts says

If the cookie expires after 1 day and you don’t have too many messages you don’t have to delete them explicitly. If you have a couple of messages I would go with pixelentitys approach.

5 months ago
1203 posts
  • Has been a member for 3-4 years
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a File in an Envato Bundle
  • Envato Staff
  • Reviewer
  • Lead Reviewer
  • Author had a Free File of the Month
  • Beta Tester
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Malaysia
  • Referred between 200 and 499 users
kailoon says

You guys are awesome! Thanks for the great help and feedback :)

End up, I am not using timestamp or reset cookie. I create a variable for the client to change the cookie name. So, the new box always get published.

I think this meet the client expectation. - User can close and never see the box until cookie expired. - Client can always update the message and user will see it as soon as it is published.

Anyway, thanks a lot for the advices :)

5 months ago
kailoon is an Envato staff member
by
by
by
by
by