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.} |
时间: 2024-09-17 04:03:36