显示标签为“浏览器”的博文。显示所有博文
显示标签为“浏览器”的博文。显示所有博文

2009/02/25

cookie读写类

JavaScript语言: cookie操作代码

smartclick_Cookie = {

    get: function(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = smartclick_Cookie.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    },
    set: function(key, value, ttl, path, domain, secure) {
        cookie = [key+'='+    encodeURIComponent(value),
                   'path='+    ((!path   || path=='')  ? '/' : path),
                   'domain='+  ((!domain || domain=='')?  window.location.hostname : domain)];
       
        if (ttl)         cookie.push( 'expires='+smartclick_Cookie.hoursToExpireDate(ttl));
        if (secure)      cookie.push('secure');
       
        return document.cookie = cookie.join('; ');
    },

    //@param integer    ttl        Time To Live (hours)
    hoursToExpireDate: function(ttl) {
        if (parseInt(ttl) == 'NaN' ) return '';
        else {
            now = new Date();
            now.setTime(now.getTime() + (parseInt(ttl) * 60 * 60 * 1000));
            return now.toGMTString();
        }
    },
    trim: function( text ) {
        return (text || "").replace( /^\s+|\s+$/g, "" );
    }
}

几点说明:
1.ttl生存期时间单位是小时。
2.get方法的原理是字符串匹配,对[key=]value的中括号部分进行匹配,优于使用正则进行匹配,正则如有特殊字符的情况会很麻烦。

2008/12/16

我是傲游的忠实用户

傲游带给我的良好体验:



  1. 自定义界面按钮。大多数情况我只使用键盘的快捷操作,很多按钮使用不到,那就无需显示出来。

  2. 网络收藏功能。收藏夹内容便自动同步,在公司和在家同步体验。尤其在重装系统忘记备份收藏夹时。

  3. 键盘Ctrl+左右键,可以切换标签页。

  4. 拖动链接会在新窗口打开。

  5. 鼠标动作。用的最多的是后退。

  6. Ctrl+N新标签页。T太远,且在左手范围。

如果google chrome能够提供给我同样的功能,也许会转到google chrome。chrome能不能起个中文名(chrome好像有中文名了:谷歌浏览器)?记得在高一时接触到google,非常痛恨它没有中文名字。