I have an "Enter Site" button leading to my splash page and I would like to to only appear on the first visit, not on refreshes. Is there a way I can send a cooki开发者_运维技巧e on the click event of my button? I've found similar tutorials but nothing exact
It really depends on how you want to show/hide the splash page.
To set a cookie when a user clicks on an element, you'd do something like this, if I'm remembering it right:
document.getElementById("myButton").onclick =
function() {
document.cookie = "cookie_name_goes_here=cookie_data_goes_here";
};
Just set it on page load:
document.cookie = 'was_here=true; expires=Thu, 15 Apr 2020 20:00:00 GMT; path=/'
Larger solution:
<script type="text/javascript">
var pCs = document.cookie.split(';');
for (var ii=0; ii < pCs.length; ii++)
{
var pCookie = pCs[ii].split('=');
if (pCookie[0] == 'was_here')
{
location.href='next.html'; // or whatever you want to do.
}
}
document.cookie = 'was_here=true; expires=Thu, 15 Apr 2020 20:00:00 GMT; path=/'
</script>
精彩评论