This example shows how to get, set, and remove cookies using the YUI Cookie utility.
Keep an eye on the Logger console at right to view the log messages associated with this example.
Click the buttons to interact with the cookie:
This example consists of three buttons, each of which performs one of the basic cookie functions: getting a value, setting a value, and removing a value. The first button, "Get Value", retrieves the value of a cookie and displays it in an alert:
The second button, "Set Random Value", creates a random value and sets the cookie's value equal to it:
After clicking this button, you can go back and click "Get Value" to see the new value that was assigned to the cookie (you can also check the logger output).
The third button, "Remove Value", completely removes the cookie from the page:
When this button is clicked, it removes the cookie. If "Get Value" is clicked immediately afterwards, the
value should be
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.