Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check browser has enabled cookies?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 136
    Comment on it

    Check cookies are enabled or disabled on the browser :

    In web applications sometimes we need to save some information on client side, to save data on client side the most popular option is cookies. But the user can enable or disable cookies on the browser. So in case if user has disabled cookies you can lost the information. So in case when you want to save data in cookies you can first check the browser that cookies are enabled or not.

     

    So to check the browser has cookies enabled or not we can use the property 'cookieEnabled' of 'navigator' object. The 'cookieEnabled' property returns the true and false. If cookies are enabled then it returns 'true' otherwise 'false'.

    Syntax of using cookieEnabled property :

    navigator.cookieEnabled

     

    Example of using cookieEnabled property : Now in this example I will show how to use the cookieEnabled property to know the browser has enabled or disabled the cookies.

     

    Sample.html

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Is your browser has enabled cookies? To check press the Check button</p>
    <button onclick="isBrowserEnableCookie()">Check</button>s
    <p id="container"></p>
    
    <script>
    function isBrowserEnableCookie() {
        container = document.getElementById("container");
        container.innerHTML = navigator.cookieEnabled;
    }
    </script>
    
    </body>
    </html>

    The above HTML will print the True or False. If the cookies are enabled then it will print TRUE and if not then FALSE.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: