Check if cookies are enabled on client side
Using just Javascript (with the help of jQuery and the jQuery cookie plugin), this bit of code will do the trick on checking whether the user's browser accepts cookies or not. This is helpful for posting a warning message on a login screen or when adding things to a shopping cart, etc.
<script>
jQuery(document).ready(function()
{
var TEST_COOKIE = 'test_cookie';
jQuery.cookie( TEST_COOKIE, true );
if ( jQuery.cookie ( TEST_COOKIE ) )
{
jQuery.cookie( TEST_COOKIE, null );
alert( 'Good news, cookies are enabled.' );
}
else
{
alert( 'Cookies are not enabled. Please enable and try again.' );
}
}
</script>
Labels: code, javascript

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home