You are here: Reference > JavaScript > client-side > browser > properties > cookieEnabled (clientInformation, navigator)

cookieEnabled property (clientInformation, navigator)

Browser support:
Retrieves a Boolean value that indicates whether cookies are enabled in the browser.
If cookies are enabled, you can use the cookie property to set or retrieve the cookies stored for the current document. For a detailed description about cookies, see the page for the cookie property.
To get various information about the browser and the operating system of the user, please see the page for the navigator object and the example below. If you need to detect the type of the user's browser, please see the page for Browser detection.

Syntax:

object.cookieEnabled;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Boolean, one of the following values:
false
Cookies are disabled.
true
Cookies are enabled.
Default: this property has no default value.

Example HTML code 1:

This example shows how to create, modify and remove cookies:
<head>
    <script type="text/javascript">
        function TestCookies () {
            if (!window.navigator.cookieEnabled) {
                alert ("Please enable cookies in your browser first!");
                return;
            }
            
            var info = document.getElementById ("info");

                // create a cookie with no expiration time
            document.cookie = "fruit=peach"; 

                // dump the current cookies
            info.innerHTML += document.cookie + "<br />";

                // create a cookie with expiration time
            document.cookie = "price=23; expires=Mon, 23 Jul 2040 22:00:00 GMT"; 

                // dump the current cookies
            info.innerHTML += document.cookie + "<br />";

                // modify the value of a cookie
            document.cookie = "fruit=apricot"; 

                // dump the current cookies
            info.innerHTML += document.cookie + "<br />";

                // delete a cookie (expiration date in the past)
            document.cookie = "fruit=; expires=Thu, 01 Jan 1970 00:00:00 GMT"; 

                // dump the current cookies
            info.innerHTML += document.cookie + "<br />";
        }
    </script>
</head>
<body onload="TestCookies ();">
    <div id="info" style="background-color:#e0c0a0;"></div> 
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content