JavaScript Program to Create a Persistent Cookie

Write a JavaScript program to create a persistent cookie.



Source Code
<html>
<head>
    <title>Persistent Cookie Example</title>
    <script>
        function WriteCookie()
        {
            var expireDate = new Date();
            expireDate.setMonth(expireDate.getMonth() + 1);

            with (document.CookieWriter)
            {
                document.cookie = "ItemName=" + "; expires=" + expireDate.toGMTString() + ";";
                alert("Cookie Written");
            }
        }
    </script>
</head>
<body>
<form name="CookieWriter" action="" >
    Enter the item name:<input type="text" name="customer" onchange="WriteCookie()"/>
</form>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store