Delete cookie button for W3 school cookie

javascript delete cookie
javascript cookies
php delete cookie
how to delete a cookie
jquery set cookie
change cookie value javascript
javascript check if cookie exists
set-cookie in browser

Yes I know W3school, you all hate it. I do too at times but it is helping me now. How do you make a delete cookie button for their website? The cookie example that they have on their website:

<!DOCTYPE html>
<html>
<head><script>

function setCookie(cname,cvalue,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}

function getCookie(cname)
{
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) 
  {
  var c = ca[i].trim();
  if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
return "";
}

function checkCookie()
{
var user=getCookie("username");
if (user!="")
  {
  alert("Welcome again " + user);
  }
else 
  {
  user = prompt("Please enter your name:","");
  if (user!="" && user!=null)
    {
    setCookie("username",user,30);
    }
  }
}

</script></head>

<body onload="checkCookie()"></body>
</html>

I have tried to delete it using:

<input type="button" value ="delte cookie" onclick= '"document.cookie = "username=; expires=Thu, 01 Jan 2000 00:00:00 GMT";'/>

but it does not delete the cookie. I have tried other ways to delete cookies of one site but they do not work. Does anyone have html for a button that deletes the cookie of that site?

Try this,

 <input type="button" value ="delete cookie" onclick= 'document.cookie = "username=; expires=Thu, 01 Jan 2000 00:00:00 GMT";'/>

JavaScript Cookies, JavaScript can create, read, and delete cookies with the document.cookie property. (in UTC time). By default, the cookie is deleted when the browser is closed:. I have tried to delete it using: <input type="button" value ="delte cookie" onclick= '"document.cookie = "username=; expires=Thu, 01 Jan 2000 00:00:00 GMT";'/> but it does not delete the cookie. I have tried other ways to delete cookies of one site but they do not work. Does anyone have html for a button that deletes the cookie of that site?

Found this a long time ago.... it works like a charm.

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

PHP setcookie() Function, Example. Several expire dates for cookies: <?php $value = "Hello world!"; // cookie will expire when the� In Control Panel, click on Uninstall a program 3. In the Programs and Features window, right click on apps that may be related with Cookies Reset Button extension, then click Uninstall/Change. Then select Uninstall option.

Add this function on delete cookie button's onclick event

function delete_cookie(name){
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}

JavaScript Cookies, Setting cookies; Create and delete cookies; Cookies a real example Click on privacy and select advanced button, another new window will come, from "http ://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html� What is a Cookie? A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

PHP 5 Cookies, Create Cookies With PHP. A cookie is created with the setcookie() function. Syntax. setcookie(name, value, expire, path, domain� To create cookie, click on the Create Cookie button. After clicking on Create Cookie button, enter the value (name) of the cookie as shown in the following figure: Now, click on OK button to successfully create your cookie. To delete cookie, just click on the Delete Cookie button.

PHP 5 Cookies, Create Cookies With PHP. A cookie is created with the setcookie() function. Syntax. setcookie(name, value, expire, path, domain� Deleting a Cookie. Sometimes you will want to delete a cookie so that subsequent attempts to read the cookie return nothing. To do this, you just need to set the expiry date to a time in the past. Example. Try the following example. It illustrates how to delete a cookie by setting its expiry date to one month behind the current date.

JavaScript and Cookies, JavaScript can read, create, modify, and delete the cookies that apply to the " text" name = "customer"/> <input type = "button" value = "Set Cookie" onclick� Delete Cookies with JSP. To delete cookies is very simple. If you want to delete a cookie, then you simply need to follow these three steps − Read an already existing cookie and store it in Cookie object. Set cookie age as zero using the setMaxAge() method to delete an existing cookie. Add this cookie back into the response header. Example

Comments
  • There are too many double quotes " in the onclick code
  • @user2330624, Yes. You may have missed to add that.!