1

这是显示 URL 和删除 cookie 的删除图像的代码。添加和显示功能正在工作,但如何删除?

function backLinks(){
    var pathname = window.location;
    var patientName = document.getElementById("general:patientDetailName").value;
    var cookieTimeVal = jQuery.cookie('PCC_Back_Button');
    if( cookieTimeVal== null){
        cookieTimeVal ="";
    }
    // for writing Cookie
    var stringCookie = "<span class='backLinkText1'><img src='../images/deleteImg.png' alt='' class='backLinkDeleteButton' onClick='deleteBackLink()'/></span><a class='backLinkText' href=\""+pathname+"\"> Patient History For \""+patientName+"\"</a>"+cookieTimeVal;
    jQuery.cookie('PCC_Back_Button', stringCookie , { expires: 1 });

    // read Cookie and set in HTML
    jQuery('#backButtonSpan').append(
        jQuery('<div>').attr({style:'padding-top:-10px;' }).append(cookieTimeVal)
    );
}

**

function deleteBackLink(val){
        jQuery.cookie(val, null);
    }

**

如何创建删除函数以及传递给它的参数是什么?

4

3 回答 3

2

得到了正确答案...

在此我将替换 cookie 并删除内部 html

 function backLinks(stringValueAndName, patientName, patientDOB){
                var pathname = window.location;
                var cookieTimeVal = jQuery.cookie('PCC_Back_Button');
                if( cookieTimeVal== null){
                    cookieTimeVal ="";
                }

                var time = new Date();
                var spanId = time.getTime();

                // for wright in Cookie
                var stringCookie = "<span id ="+spanId+"> <img src='../images/deleteImg.png' class='backLinkDeleteButton' onClick='deleteBackLink("+spanId+")'/><a class='backLinkText' href=\""+pathname+"\">"+stringValueAndName +patientName+' ('+patientDOB +')'+"\</a></span>"+cookieTimeVal;
                jQuery.cookie('PCC_Back_Button', stringCookie , { expires: 1 });
                // read Cookie and set in HTML
                jQuery('#backButtonSpan').append(
                        jQuery('<div>').attr({style:'padding-top:-10px;' }).append(cookieTimeVal)
                    );
            }
    function deleteBackLink(val){
        jQuery('#'+val).remove();
        var stringCookie = jQuery('#backButtonSpan div').html();
        jQuery.cookie('PCC_Back_Button', stringCookie , { expires: 1 });
    }
于 2013-01-25T07:15:38.667 回答
0

要使用 jQuery 删除 cookie,请将值设置为 null:

jQuery.cookie("name", null);

因此,您的函数将起作用 - 只需将 cookie 名称作为参数传递:

deleteBackLink("name");
于 2013-01-25T05:30:15.627 回答
0

它没有。饼干就是饼干。

The closest it comes is the HTTP Only flag, which allows a cookie to be hidden from JavaScript(mean client side). (这为 XSS cookie 盗窃提供了一点防御)。

饼干就是饼干。(Again, client side code can't touch an HTTP only cookie)

于 2013-01-25T06:46:07.143 回答