X
Publisher: Sigit purnomo kangsigit.com@gmail.com

Save and Delete Cookies Using Javascript

You can save something with javascript until the next few days or even up to several years.
In this tutorial we are equipped also with a button to delete cookies.

Here are the codes

JAVASCRIPT

<script language="javaScript" type="text/javascript">

function gaeCookie() {
    index = document.cookie != document.cookie ? document.cookie.indexOf(cookieCrot) : -1, -1 == index && (simpenCookie = document.formCookie.inputCookie.value, document.cookie = cookieCrot + "http://www.kangsigit.com" + simpenCookie + "; expires=Monday, 04-Apr-2020 05:00:00 GMT") //Cookie Saved)
}

function busekCookie() {
    index = document.cookie != document.cookie ? document.cookie.indexOf(cookieCrot) : -1, -1 == index && (simpenCookie = document.formCookie.inputCookie.value, document.cookie = cookieCrot + "http://www.kangsigit.com" + simpenCookie + "; expires=Monday, 04-Apr-2015 05:00:00 GMT") //Cookie Removed
}

function loadCookie(a) {
    for (var b = !1, c = 0, d = 0, e = document.cookie, f = 0; f <= e.length;) {
        if (c = f, d = c + a.Length, e.substring(c, d) == a) {
            b = !0;
            break
        }
        f++
    }
    return b ? (c = d + 1, d = document.cookie.indexOf(";", c), d < c && (d = document.cookie.length), document.cookie.substring(c, d)) : ""
}

function getName() {
    return document.cookie ? (index = document.cookie.indexOf(cookieCrot), -1 != index ? (namestart = document.cookie.indexOf("", index) + 35, nameend = document.cookie.indexOf(";", index), -1 == nameend && (nameend = document.cookie.length), judInfoNULL = document.cookie.substring(namestart, nameend)) : "<h3>Hay, Tulis Sesuatu Ya</h3><p>Tulisan kamu akan muncul disini lho...</p>") : "<h3>Hay, Tulis Sesuatu Ya</h3><p>Tulisan kamu akan muncul disini lho...</p>"
}
var simpenCookie;
cookieCrot = "cookieName";
var judInfoNULL;
judInfoNULL = getName(), ketInfoNULL = loadCookie("cookieName"), "cookieName" == judInfoNULL && (judInfoNULL = "noNE"), document.write("<p style='color:red'>" + judInfoNULL + "</p>");

</script>

HTML

<form name="formCookie">
<input type="text" name="inputCookie" style="width:60%;" maxlength="20" placeholder="TULISAN"/>
<input type="button" value="Simpan" onClick="gaeCookie()"/>
<input type="button" value="Hapus" onClick="busekCookie()"/>
</form>

EXAMPLE:
Cara Menyimpan Cookie Website dengan Form Input Button

Advertisement

no image
Add Comments
0 Comments
Click Here to Add Comments

No Comment