cookie and Session in JS(practical 10)

 avatar
Rohit143
html
2 years ago
1.4 kB
6
Indexable
Never
<html>
<head>
    <script>
        function create() {
            var cookies = document.getElementById("user").value;
            document.cookie = "username = " + cookies + ";";
            alert("Cookie Created" + document.cookie);
            document.getElementById("user").value = "";
        }
        function read() {
            var x;
            if (document.cookie == "") {
                x = "";
                alert("Cookie Not Found");
            }
            else {
                x = document.cookie;
                alert(" " + x);
            }
        }
        function del() {
            if (document.cookie != "") {
                var d = new Date();
                d.setTime(d.getTime() - (1000 * 60 * 60 * 24))
                alert("Cookie Delete");
            }
            else {
                alert("First add cookie");
            }
        }
    </script>
</head>

<body>
    <center>
        <h1>CSS : Practical No 10</h1>
        <h2>Develop a webpage for creating session and persistent cookies. Observe the effect with
            Browser Cookie Settings.</h2>
        <br><br>
        Enter Username : <input type="text" id="user">
        <input type="button" onclick="create()" value="Create">
        <input type="button" onclick="read()" value="Reading">
        <input type="button" onclick="del()" value="Delete">
    </center>
</body>

</html>