1

これは、Cookieを削除するためのURLと削除画像を表示するコードです。追加と表示機能は動作していますが、削除する方法は??

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

そうではありません。クッキーはクッキーです。

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 に答える
0

jQueryでCookieを削除するには、値をnullに設定します。

jQuery.cookie("name", null);

したがって、関数は機能します。Cookie名をパラメータとして渡すだけです。

deleteBackLink("name");
于 2013-01-25T05:30:15.627 に答える