1422 posts
  • Envato Staff
  • Has been a member for 5-6 years
  • Senior Reviewer
  • Sold between 10 000 and 50 000 dollars
  • Attended a Community Meetup
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
+10 more
kailoon Reviewer 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?

2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 more
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

814 posts
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
  • Serbia
  • Has been a member for 5-6 years
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.

490 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Won a Competition
  • Referred between 1000 and 1999 users
  • Author had a Free File of the Month
  • Author had a File in an Envato Bundle
  • Bought between 10 and 49 items
+3 more
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

2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 more
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.

1422 posts
  • Envato Staff
  • Has been a member for 5-6 years
  • Senior Reviewer
  • Sold between 10 000 and 50 000 dollars
  • Attended a Community Meetup
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
+10 more
kailoon Reviewer 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 :)

by
by
by
by
by
by