src/cm/media/js/lib/yui/yui_3.10.3/docs/cookie/cookie-simple-example.html
author gibus
Tue, 16 Jul 2013 14:29:46 +0200
changeset 525 89ef5ed3c48b
permissions -rw-r--r--
Upgrades to yui 3.10.3

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Simple Cookie Example</title>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
    <script src="../../build/yui/yui-min.js"></script>
    
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
    <div id="hd">
        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
    </div>
    

            <h1>Example: Simple Cookie Example</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><div class="intro">
<p>This example shows basic usage of the YUI Cookie utility. The example checks the value of a cookie and then sets it to a new value.</p>
</div>

<div class="example yui3-skin-sam">
  <pre id="results"></pre>

<script>
YUI().use('node', 'cookie', function (Y) {

    var pre = Y.one('#results'),
        log = function(str) {
            pre.append(str + '<br>\n');
        };

    var currentValue = Y.Cookie.get("example");
    log("Cookie's current value is '" + currentValue + "'");

    var newValue = "yui" + Math.round(Math.random() * Math.PI * 1000);
    log("Setting cookie's value to '" + newValue + "'");
    Y.Cookie.set("example", newValue);

});
</script>

</div>

<h2>Description</h2>

<p>This example begins by getting the value of a cookie named &quot;example&quot;. If this is the first time you've run
the example, the value should be <code>null</code>:

<pre class="code prettyprint">var currentValue = Y.Cookie.get(&quot;example&quot;);</pre>


<p>This value is shown in the browser console. Next, the cookie is set to a random value:</p>

<pre class="code prettyprint">var newValue = &quot;yui&quot; + Math.round(Math.random() * Math.PI);
Y.Cookie.set(&quot;example&quot;, newValue);</pre>


<p>When you reload the page, the value of the cookie should be the one that was just set.</p>

<p>Note: this example uses session cookies, so the value will be lost when you close the browser.</p>

<h2>Complete Example Source</h2>

<pre class="code prettyprint">&lt;pre id=&quot;results&quot;&gt;&lt;&#x2F;pre&gt;

&lt;script&gt;
YUI().use(&#x27;node&#x27;, &#x27;cookie&#x27;, function (Y) {

    var pre = Y.one(&#x27;#results&#x27;),
        log = function(str) {
            pre.append(str + &#x27;&lt;br&gt;\n&#x27;);
        };

    var currentValue = Y.Cookie.get(&quot;example&quot;);
    log(&quot;Cookie&#x27;s current value is &#x27;&quot; + currentValue + &quot;&#x27;&quot;);

    var newValue = &quot;yui&quot; + Math.round(Math.random() * Math.PI * 1000);
    log(&quot;Setting cookie&#x27;s value to &#x27;&quot; + newValue + &quot;&#x27;&quot;);
    Y.Cookie.set(&quot;example&quot;, newValue);

});
&lt;&#x2F;script&gt;</pre>

</div>
            </div>
        </div>

        <div class="yui3-u-1-4">
            <div class="sidebar">
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                        <li data-description="Demonstrates basic usage of the Cookie utility for reading and writing cookies.">
                                            <a href="cookie-simple-example.html">Simple Cookie Example</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Demonstrates using the Cookie utility to get, set and remove cookies.">
                                            <a href="cookie-advanced-example.html">Advanced Cookie Example</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Demonstrates using the Cookie utility to get and set subcookies.">
                                            <a href="cookie-subcookie-example.html">Subcookie Example</a>
                                        </li>
                                    
                                
                            </ul>
                        </div>
                    </div>
                

                
            </div>
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

<script>
YUI.Env.Tests = {
    examples: [],
    project: '../assets',
    assets: '../assets/cookie',
    name: 'cookie-simple-example',
    title: 'Simple Cookie Example',
    newWindow: '',
    auto:  false 
};
YUI.Env.Tests.examples.push('cookie-simple-example');
YUI.Env.Tests.examples.push('cookie-advanced-example');
YUI.Env.Tests.examples.push('cookie-subcookie-example');

</script>
<script src="../assets/yui/test-runner.js"></script>



</body>
</html>