0

i want hide div when the person click on it and show another div using cookies

this is work for me but it take 24 hour , i wana make it just 2 hour ?

Hide div 24hr cookie javascript?

i want make it 2 hour not 24 hour :)

Community
  • 1
  • 1
Ahmed Safadi
  • 4,402
  • 37
  • 33

1 Answers1

0
function setCookie(cname, cvalue, exdays) {
  alert("3");
  var d = new Date();
  d.setTime(d.getTime() + exdays * 60 * 1000);
  var expires = "expires=" + d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function checkCookie() {
  var username = getCookie("username");
  if (username != "") {
    alert("Welcome again " + username);
  } else {
    username = prompt("Please enter your name:", "");
    if (username != "" && username != null) {
      setCookie("username", username, 2);
    }
  }
}

The expression d.setTime(d.getTime() + exdays * 60 * 1000); calculates the expiry date in terms of minutes. setCookie("username", username, 120); here, 120 is total minutes.