views:

33

answers:

1

This works:

var d = new Date();
document.cookie = name + "=1;expires=" + d.toGMTString() + ";" + "; path=/";

But this doesn't work:

function deletecookie(name)
{
    var d = new Date();
    document.cookie = name + "=1;expires=" + d.toGMTString() + ";" + "; path=/";
}
deletecookie(name);

Why it doesn't work after wrapping in a function?

EDIT

Seems this only happens in firebug,is there some reason for it?

+1  A: 

Works fine for me in latest version of Firefox so long as you define name before hand:

<script>
var name="hello"
function deletecookie(name)
{
    var d = new Date();
    document.cookie = name + "=1;expires=" + d.toGMTString() + ";" + "; path=/";
document.write(name);
}
deletecookie(name);
</script>
JoshBerke
Does it work in firebug?I tested it in firebug