Monday, February 18, 2008

Check the browser to see whether or not cookies are allowed

To see if you can save your cookies on the client's machine, you can simply use JavaScript. I did some search on the internet and realized that some people recommend using code-behind. While there is no need when you can use JavaScript, doing so will require for the web application to post back twice.

Use the following code to specify cookies are allowed. It tries to leave a cookie on the client's machine; if it succeeds, it means cookies are enabled.

document.cookies="MyTest=Test";
if (document.cookies=="")
alert("Cookies are blocked");
else
alert("Cookies are allowed");

No comments: