tags:

views:

65

answers:

2

Is my function of creating cookie correct? and how do i delete cookie at the beginning of my program run? is there a simple coding?

function createCookie(name,value,days)

<script>
    function setCookie(c_name,value,1) {
    document.cookie = c_name + "=" +escape(value);
    }

    setCookie('cookie_name',mac);
</script>


function eraseCookie(c_name) {
    createCookie(cookie_name,"",-1);
}
+1  A: 

Here's a great reference.

jessegavin
If you don't use a library like jQuery or MooTools, use this
Infinity
A: 

Hai kennedy,

This may help you

function Delete_Cookie( name, path, domain ) 
{
   if ( Get_Cookie( name ) )
   document.cookie=name+"="+((path) ? ";path="+path:"")+((domain)?";domain="+domain:"") +
                                   ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

or

function del_cookie(name)
{
    document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
Pandiya Chendur
how do i set a function that and check what is my cookies and whether it expire yet?
kennedy
@Kennedy jason's answer might be useful
Pandiya Chendur
@Pandiya i thought of having a function to view my cookie first.. do you have any coding for that? i want to see it when everytime i visit the webpage, it automatically pop-up an alert for it.
kennedy
@kennedy ok i ll give a try for that condition and let you know ....
Pandiya Chendur
@Pandiya thanks :)
kennedy