user198729
user198729

Reputation: 63686

Having trouble with cookie operation with javascript

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?

Upvotes: 0

Views: 122

Answers (2)

Cees Timmerman
Cees Timmerman

Reputation: 19692

Firebug often causes all sorts of bugs. Try its latest version and if the problem persists, see this.

Upvotes: 0

JoshBerke
JoshBerke

Reputation: 67128

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>

Upvotes: 1

Related Questions