一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

cookie实现自动登录功能:

时间:2009-09-04 编辑:简简单单 来源:一聚教程网

cookie实现自动登录功能:

01.function getCookie( name ) { 
02.    var start = document.cookie.indexOf( name + "=" ); 
03.    var len = start + name.length + 1; 
04.    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { 
05.        return null; 
06.    } 
07.    if ( start == -1 ) return null; 
08.    var end = document.cookie.indexOf( ';', len ); 
09.    if ( end == -1 ) end = document.cookie.length; 
10.    return unescape( document.cookie.substring( len, end ) ); 
11.} 
12.function setCookie( name, value, expires, path, domain, secure ) { 
13.    var today = new Date(); 
14.    today.setTime( today.getTime() ); 
15.    if ( expires ) { 
16.        expires = expires * 1000 * 60 * 60 * 24; 
17.    } 
18.    var expires_date = new Date( today.getTime() + (expires) ); 
19.    document.cookie = name+'='+escape( value ) + 
20.        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString() 
21.        ( ( path ) ? ';path=' + path : '' ) + 
22.        ( ( domain ) ? ';domain=' + domain : '' ) + 
23.        ( ( secure ) ? ';secure' : '' ); 
24.} 
25.function deleteCookie( name, path, domain ) { 
26.    if ( getCookie( name ) ) document.cookie = name + '=' + 
27.            ( ( path ) ? ';path=' + path : '') + 
28.            ( ( domain ) ? ';domain=' + domain : '' ) + 
29.            ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 
30.}

热门栏目