1

Hi am trying to delete cookie in my application. The code i wrote here is works everything fine in chrome.The problem i'm getting is in Opera browser its removing cookie, but the application is restarting. plz help me....... Code:

-------------------------------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>
4

1 回答 1

0

以下功能将为您完成工作:

function deleteCookie(name)
{
  document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
于 2014-03-06T09:18:00.367 回答