Check if Cookies are Enabled

09Jul08

If cookies are needed you can make a page load check adding this javascript to your page !!!

<script type=”text/javascript”>
// remember, these are the possible parameters for Set_Cookie:
// name, value, expires, path, domain, secure
Set_Cookie( ‘test’, ‘none’, ”, ‘/’, ”, ” );
// if Get_Cookie succeeds, cookies are enabled, since
//the cookie was successfully created.
if ( Get_Cookie( ‘test’ ) )
{
document.write( ‘cookies are currently enabled.’ );
/*
this is an example of a set cookie variable, if
you want to use this on the page or on another script
instead of writing to the page you would just check that value
for true or false and then do what you need to do.
/*
cookie_set = true;
// and these are the parameters for Delete_Cookie:
// name, path, domain
// make sure you use the same parameters in Set and Delete Cookie.
Delete_Cookie(‘test’, ‘/’, ”);
}
// if the Get_Cookie test fails, cookies
//are not enabled for this session.
else
{
document.write( ‘cookies are not currently enabled.’ );
cookie_set = false;
}
</script>

Advertisements


2 Responses to “Check if Cookies are Enabled”

  1. 1 kunalbharati

    thanx.. was searching for this

  2. 2 worthposting

    np mate…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: