1
您好,我試圖刪除我的應用程序中的cookie。我在這裏寫的代碼是在鉻合金工作一切正常。我得到的問題是在Opera瀏覽器中刪除cookie,但應用程序正在重新啓動。 plz幫我....... 代碼:如何使用javascript刪除cookie
------------------------------- imports- -----------------
<html>
<head>
<title> Report Generation</title>
</head>
<script>
window.onload=function(){checkCookie();}
function close(){ formName.close();}
function checkCookie()
{
<%
PracticeDBHandler practiceDBHandler1 = new PracticeDBHandler();
ArrayList<PracticeBean> listPractice1 = practiceDBHandler1.getPracticeList(WFDBPool);
for (PracticeBean practiceBean1 : listPractice1) {
int pr_id1 = practiceBean1.getPr_id();
String pr_name1 = practiceBean1.getPracticeName();
%>
var cookiename=getCookie(<%=pr_id1%>);
if (cookiename!=null && cookiename!="")
{
document.getElementById(<%=pr_id1%>).checked=true;
}
else
{
document.getElementById(<%=pr_id1%>).checked=false;
}
<% }%>
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function checkBoxes(){
var result, vals = [], checkBoxName = document.forms['formName']['checkBoxName[]'];
for(var i=0,elm;elm = checkBoxName[i];i++) {
if(elm.checked) {
document.cookie=elm.value + "=" + "Value";
}
else if(!elm.checked){
var exp=new Date();
exp.setTime(exp.getTime()-1);
document.cookie = elm.value + "=" +"Value" + ";expires=" + exp.toGMTString();
}
}
result = vals.join(', ');
}
</script>
<body>
<form name="formName">
<%
PracticeDBHandler practiceDBHandler = new PracticeDBHandler();
ArrayList<PracticeBean> listPractice = practiceDBHandler.getPracticeList(WFDBPool);
for (PracticeBean practiceBean : listPractice) {
int pr_id = practiceBean.getPr_id();
String pr_name = practiceBean.getPracticeName();
%>
<input type="checkbox" name="checkBoxName[]" value="<%=pr_id%>" id="<%=pr_id%>"/> <%=pr_name%> (<%=pr_id%>)<br>
<% }%><br>
<input type="button" onclick="checkBoxes()" value="Save"/>
</form>
</body>
</html>
可能重複(HTTP ://stackoverflow.com/questions/2144386/javascript-delete-cookie) – 2013-03-22 07:50:31