A cookie is a small object allows servers to store users information on user machine. Cookies are stored in the partition assigned to the web servers domain. All cookies for that domain are sent in every request to that web server. When a user visits a page, his name can be stored in a cookie. Next time when user visits, the cookie recognizes user on the server. Cookies help in to identify user uniquely for session management.
Using Javascript we can detect if the cookie support is enabled or not. The following example demonstrates this:
Test Cookie Support using JavaScript Example
<!DOCTYPE html> <head> <TITLE>Example to detect Cookie Support</TITLE> </head> <body> <script type="text/javascript"> var cookieEnabled=(navigator.cookieEnabled)? true : false document.writeln("<b>cookieEnabled status </b>--"+cookieEnabled); //if (cookieEnabled) //if cookies are enabled on client's browser //do whatever </script> </body> </html>
Cookie Support using JavaScript Demo
- Save the file as cookiesupportexample.html in your system.
- Just open the file in the browser, you will see the below picture in the browser. Note that the browser must support HTML specification.