diff -r 322d0feea350 -r 89ef5ed3c48b src/cm/media/js/lib/yui/yui_3.10.3/docs/cookie/cookie-simple-example.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/cookie/cookie-simple-example.html Tue Jul 16 14:29:46 2013 +0200 @@ -0,0 +1,164 @@ + + + + + Example: Simple Cookie Example + + + + + + + + + + +
+
+

+
+ + +

Example: Simple Cookie Example

+
+
+
+
+

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.

+
+ +
+

+
+
+
+
+ +

Description

+ +

This example begins by getting the value of a cookie named "example". If this is the first time you've run +the example, the value should be null: + +

var currentValue = Y.Cookie.get("example");
+ + +

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

+ +
var newValue = "yui" + Math.round(Math.random() * Math.PI);
+Y.Cookie.set("example", newValue);
+ + +

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

+ +

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

+ +

Complete Example Source

+ +
<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>
+ +
+
+
+ +
+ +
+
+
+ + + + + + + + + + +