How can I create and read a value from a cookie in JavaScript?
You can use my cookie ES module for get/set/remove cookie.
In your head tag, include the following code:
or
Now you can use window.cookie for store user information in web pages.
Is the cookie enabled in your web browser?
returns {boolean} true if cookie enabled.
Example
if ( cookie.isEnabled() )
console.log('cookie is enabled on your browser');
else
console.error('cookie is disabled on your browser');
Set a cookie.
name: cookie name.
value: cookie value.
Example
cookie.set('age', 25);
get a cookie.
name: cookie name.
defaultValue: cookie default value. Default is undefined.
returns cookie value or defaultValue if cookie was not found
Example
var age = cookie.get('age', 25);
Remove cookie.
name: cookie name.
Example
cookie.remove( 'age' );
Example of usage