I am looking for a way to create/detect a cookie on a local host in javascript. Basically, if a cookie with a specified name “foo” exists for the session, do nothing. If no cookie exists, then create a new cookie named foo and populate it with a guid. How can i do this in javascript?
Thanks
Reading cookies from javascript requires a bit of string parsing. There are a number of good libraries that make this task easier, but you can use code similar to the following to get and set cookie values
Generating a Guid in javascript is a bit harder. This guy has a nice library you can include that will generate good GUIDs. I know there are also some jQuery plugins that were created with a similar purpose, but I have not used them.
If you include the following scripts, along with the functions above it should do what you want.