| DEVPPL http://www.devppl.com/forum/ |
|
| On page load, if cookie set then hide div? http://www.devppl.com/forum/viewtopic.php?f=49&t=13695 |
Page 1 of 1 |
| Author: | purplemonster [ Mon Jun 15, 2009 10:15 am ] |
| Post subject: | On page load, if cookie set then hide div? |
Hi there, I'm not very good with Javascript 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! |
|
| Author: | panzer [ Tue Jun 16, 2009 10:38 am ] |
| Post subject: | Re: On page load, if cookie set then hide div? |
Not sure if it's what you're after, but may something like this will help. Code: ... <script language="javascript"> function foo() { if(document.cookie != "" && document.cookie != null) { document.getElementById("d").style.visibility = "hidden"; alert(document.cookie); } else { var ndate = new Date(); ndate.setDate(ndate.getDate() + 1); document.cookie = "test=cookie;expires=" + ndate.toGMTString(); document.getElementById("d").innerHTML = "no cookie"; } } </script> </head> <body onload="foo()"> <div id="d"></div> ... HTH |
|
| Author: | rangana [ Mon Jun 22, 2009 7:44 am ] |
| Post subject: | Re: On page load, if cookie set then hide div? |
Hi Panzer, One thing, please avoid using "language" attribute for your script tags. It's deprecated. |
|
| Page 1 of 1 | All times are UTC + 1 hour |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|