To check the cookie enabled you can use the javascript code in the web page header to send the alert message to the user for enabling the browser cookies.
What are cookies? Cookies are small text files that server sends to the client’s browser to store some text message at the client end. Generally, cookies are used to store the website or user information on client’s PC that is frequently used on the web pages e.g. username, shopping carts etc. Cookies are also used to track the visitors, visitor’s loyalty for tracking returning or new visitors. Cookies also provide the help in the web site login feature of remember me to auto login the user next time when he visits the site from the same PC.
To perform the above actions by using cookies is only possible if the client’s browser is cookie enabled.
Javascript navigator Object can be used to detect whether the browser cookies are enabled or not.
Javascript Code to check cookieEnabled
<html>
<head>
<title>detect browser cookies</title>
<script language="javascript" type="text/javascript">
<![CDATA[
function detect() {
if (navigator.cookieEnabled) {
alert('Your browser has cookies enabled.');
}
else {
alert('Your browser has cookies disabled.');
}
}
]]>
</script>
</head>
<body onload="detect();">
</body>
</html>
Continue to next tutorial: Javascript Browser Detection to learn how to detect web browser.