PDA

View Full Version : On page load, if cookie set then hide div?


GuitarLord
06-14-2009, 01:48 PM
Hi there,

I'm not very good with ASP so I need you help for page on my website...

Basically what I need to do is to make a DIV shown only first time someone visits page, and then when he/she revisit it I want that same DIV hidden, and I want it hidden for next 24 hours... so in that way DIV would be shown only once a day, and only on first page load.

So to make that happen I need to do fallowing, and I would need your help for that: I need a script that on a page load checks if cookie (which is 24h cookie) is set, if it is then it should hide that DIV, if it is not set then it should set it, so that DIV would be hidden on next page load...

Can someone help me with this, cause I am getting mad trying to do this whole day :/

Thanks people!

Old Pedant
06-14-2009, 07:47 PM
Trivial.

<%
If Trim("" & Request.Cookie("showdiv")) <> "shown" Then
Response.Cookie("showdiv") = "shown"
Response.Cookie("showdiv").expires = DateAdd("n", 23*60+59, Now())
%>
<div>This is it!</div>
<%
End If
%>

Note that the cookie expires in 23 hours and 59 minutes from Now(). Adjust that part as needed. "n" is the abbreviation for "miNutes" when using DateAdd. You would use "h" if you wanted to add hours.