Search code examples
javascripthtmlcookieslocal-storagesession-cookies

How to change the cookie to session in javascript


enter image description here

I am new to cookies. I have the existing code using cookies. I want to change the cookie to the session storage now. How to do it

if (My.Cookie.getCookie('cookie1') !== "true") {

}

if (!data) {
  // some code
} else {
   My.Cookie.setCookie('cookie1', "true");
}

Solution

  • You can use

    sessionStorage.SessionName = "SessionData"

    sessionStorage.getItem("SessionName")

    sessionStorage.setItem("SessionName","SessionData");