Skip to main content

Javascript Cookies



    <script type="text/javascript">
        function createCookie() {
            document.cookie = "CookieName=CookieValue;" + "expires=Sat, 16 May 2020 18:40:22 GMT";
        }
        function getCookieValue(key) {
            currentcookie = document.cookie;
            if (currentcookie.length > 0) {
                firstidx = currentcookie.indexOf(key + "=");
                if (firstidx != -1) {
                    firstidx = firstidx + key.length + 1;
                    lastidx = currentcookie.indexOf(";", firstidx);
                    if (lastidx == -1) {
                        lastidx = currentcookie.length;
                    }
                    return unescape(currentcookie.substring(firstidx, lastidx));
                }
            }
            return "";
        }
    </script>

Comments