详细方法说明参见:http://code.google.com/p/cookies/wiki/Documentation
提供方便方法操作cookie :
var newOptions = {domain:'*.mydomain.com',path:'/somedir',expiresAt:new Date(2011,1,1),secure:true};//声明cookie的保存周期
$.cookies.get()
$.cookies.filter()
$.cookies.set()
$.cookies.del()
$.cookies.test()
$.cookies.setOptions()
========================================================================================
我的应用(半小时后自动跳转至sessionView.jsp提示session过期):
1.cssBasePage.jsp
<!-- session失效判断 --> <%--页面不能出现<meta http-equiv="X-UA-Compatible" content="IE=7"/>--%> <script type="text/javascript"> function sessionView(){ var sessionTime = $.cookies.get("sessionTime"); if(sessionTime==''){ $.cookies.set("sessionTime","1"); } else{ $.cookies.set("sessionTime",sessionTime+1); } if(sessionTime>31*60){ var mysession = '${sessionScope.user}'; if(mysession==''){ $.cookies.del("sessionTime"); window.parent.parent.location .replace("<%=path%>/jsp/phone/login/sessionView.jsp"); //window.parent.frames['main'].location .replace("<%=path%>/jsp/phone/login/sessionView.jsp");//main打开 } else{ $.cookies.del("sessionTime"); } } } sessionView(); setInterval("sessionView()",1000); </script>
2.sessionView.jsp
<script type="text/javascript">
function toLogin(){
window.parent.parent.location.replace("<%=path%>");
}
</script>
</head>
<body>
<table>
<tr>
<td>
Session失效,请重新登录!
<a href="" οnclick="toLogin()">登录</a>
</td>
</tr>
</table>
</body>
</html>