返回顶部

收藏

evercookie 使用方法示例

更多

evercookie 是一套想揠法在?盂器上留下可供硷?的痕叟的 javscript library,支援非常多方法,想蓖揠法?生?似 HTTP cookie 的效果。目前实现的方法借助了 flash 的支持。

<script type=\"text/javascript\" src=\"jquery-1.4.2.min.js\"></script>
<script type=\"text/javascript\" src=\"swfobject-2.2.min.js\"></script>
<script type=\"text/javascript\" src=\"evercookie.js\"></script>

<script>
    var ec = new evercookie();

    // set a cookie \"id\" to \"12345\"
    // usage: ec.set(key, value)
    ec.set(\"id\", \"12345\");

    // retrieve a cookie called \"id\" (simply)
    ec.get(\"id\", function(value) { alert(\"Cookie value is \" + value) });

    // or use a more advanced callback function for getting our cookie
    // the cookie value is the first param
    // an object containing the different storage methods
    // and returned cookie values is the second parameter
    function getCookie(best_candidate, all_candidates)
    {
        alert(\"The retrieved cookie is: \" + best_candidate + \"\\n\" +
            \"You can see what each storage mechanism returned \" +
            \"by looping through the all_candidates object.\");

        for (var item in all_candidates)
            document.write(\"Storage mechanism \" + item +
                \" returned: \" + all_candidates[item] + \"<br>\");
    }
    ec.get(\"id\", getCookie);

    // we look for \"candidates\" based off the number of \"cookies\" that
    // come back matching since it\'s possible for mismatching cookies.
    // the best candidate is most likely the correct one
</script>
//该片段来自于http://outofmemory.cn

标签:javascript,网络

收藏

0人收藏

支持

0

反对

0

发表评论