Creating and Reading Cookies in JavaScript
Cookies are small text files that websites use to store information on users' devices. In JavaScript, there are several functions you can use to work with cookies.
Creating a Cookie
To create a cookie, use the createCookie function. This function takes three parameters:
Example:
createCookie("user_name", "John Doe", 30);
Reading a Cookie
To read a cookie, use the getCookie function. This function takes one parameter:
Example:
var username = getCookie("user_name");
The above code assigns the value of the "user_name" cookie to the username variable. If the cookie does not exist, the username variable will be an empty string.
The above is the detailed content of How Do I Create and Read Cookies in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!