MooTools Cookie Object PRO

MooTools provides us with Cookie, a global object that provides us with a clean and simple access to the cookies on our web browser.

The following code sample shows how simple it is to create a new cookie and how simple it is to read the value of a cookie that already exists.

<!DOCTYPE html>
<html>
<head>
    <title>cookie demo</title>
    <script type="text/javascript" src="mootools-core-1.4.5-full-nocompat.js"></script>
    <script type="text/javascript">
        function saveCookie()
        {
            Cookie.write(
                    document.myform.savekey.value,
                    document.myform.savevalue.value,
                    {duration:1}
                );
        }
        function getCookie()
        {
            var key = document.myform.getkey.value;
            document.myform.getvalue.value = Cookie.read(key);
        }
    </script>
</head>
<body>
    <form name="myform">
        <p>
            key: <input type="text" name="savekey"/>
            <br/>
            value: <input type="text" name="savevalue" />
            <br/>
            <input type="button" value="save" onClick="saveCookie()"/>
        </p>
        <p>
            key: <input type="text" name="getkey"/>
            <br/>
            <input type="button" value="get" onClick="getCookie()" />
            <br/>
            <input type="text" name="getvalue"/>
        </p>
    </form>
</body>
</html>

The following video clip overviews this code sample, shows its execution and explains each and every part of it.

You can find more video clips, code samples and presentations for learning how to use the MooTools JavaScript framework in my free courses web site at http://abelski.lifemichael.com.

Share:

banner for the css playlist in hebrew life michael courses for programmers

The First Steps in CSS

Learn CSS using our our videos (in Hebrew) on the CSS (he) playlist on youtube. Do it now. Do it for free.

Good Trainers Collaborate with Others

It is always essential to keep an open mind and learn from others. This applies to everyone, including teachers and especially software development trainers. Software

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences