1482 posts
  • Envato Team
  • Author Level 6
  • Meetup Participant
  • Affiliate Level 5
+14 more
kailoon
Envato team
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?

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 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

815 posts
  • Affiliate Level 1
  • Author Level 5
  • Collector Level 1
  • Freebie
+3 more
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.

501 posts
  • Affiliate Level 7
  • Author Level 10
  • Collector Level 2
  • Top Monthly Author
+10 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

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 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.

1482 posts
  • Envato Team
  • Author Level 6
  • Meetup Participant
  • Affiliate Level 5
+14 more
kailoon
Envato team
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