Page 1 of 1

tbfunction_createCookie 'session'

PostPosted: Fri Dec 06, 2024 8:06 am
by John Robin Dove
Hi Clifton,
I decided to set the useStorage parameter to 'session' when creating a cookie but it doesn't seem to create a cookie. If I don't include the useStorage parameter it functions as planned. Perhaps I am doing something wrong. Here is my code:
Code: Select all
 (CREATING)tbfunction_pgTBObjSet("pleaseWait", "visible", true);
  //tbfunction_createCookie("reloaded", "OK", 0, ""); //This one works
  tbfunction_createCookie("reloaded", "OK", 0, "session"); // this one doesn't
  window.location.reload();
(READING)
const str = tbfunction_readCookie("reloaded");
    console.log("cookie says " + str)
      if (str == "OK")
      {
      tbfunction_pgTBObjSet("pleaseWait", "visible", true);
      //tbfunction_eraseCookie("reloaded"); //This one works
      tbfunction_eraseCookie("reloaded", "session");
      console.log("clicking");
      tbfunction_pgTBObjSet("textOrProject", "click");
      }
      else
      {
      this.hideWait();
      this.ownerCode();  //ownerCode checks whether personal password has been created.
      }

Re: tbfunction_createCookie 'session'

PostPosted: Fri Dec 06, 2024 10:21 am
by Clifton
What I believe is happening in your case is that when you read the cookie, you are not telling the readCookie() function from where to retrieve it.

Example:
    tbfunction_createCookie( "myTest", "I am a stored cookie.", 0, "session" );
    setTimeout( () => {
                let tmp = tbfunction_readCookie( "myTest", "session" ); //you may be missing the "session" directive when you read the cookie
                alert( tmp );
            }, 500 );


I tested the above script with all the cookie storage locations: "local", "session", and "private"
and it works perfectly.

You must also tell eraseCookie() which storage location to use when deleting a cookie.
    tbfunction_eraseCookie( "myTest", "session" );

 

Re: tbfunction_createCookie 'session'

PostPosted: Fri Dec 06, 2024 11:21 am
by John Robin Dove
OK. Thank you.