访问完一个网页后,如何把这个网页的COOKIE删除呢?

解决方案 »

  1.   

    http://www.360doc.com/content/09/1211/09/799_10843526.shtml
      

  2.   

    THANKS oldmanzhao, 方法不错。不过这会删掉所有的COOKIE,不过我只想删除我自己访问的那个。
    最好是在MSHTML的接口中直接删除的, 我查看了IHTMLDocument2接口,没查到相关的命令呀
      

  3.   

    IHTMLDocument2::cookie Property--------------------------------------------------------------------------------Sets or gets the string value of a cookie.SyntaxHRESULT IHTMLDocument2::get_cookie(BSTR *p);HRESULT IHTMLDocument2::put_cookie(BSTR v);
    Parametersp
    Pointer to a variable of type BSTR that receives the name=value; pairs, plus any of the values listed in Possible Values. 
    v
    BSTR that specifies the name=value; pairs, plus any of the values listed in Possible Values. 
    Possible Valuessecure; If you set a cookie as secure;, the stored cookie information can be accessed only from a secure environment. 
    expires=date; If you set no expiration date on a cookie, it expires when the browser closes. If you set an expiration date, the cookie is saved across browser sessions. If you set an expiration date in the past, the cookie is deleted. Use Greenwich Mean Time (GMT) format to specify the date.  
    domain=domainname; If you set the domain of the cookie, pages on a domain made up of more than one server can share cookie information.  
    path=path; If you set a path for the cookie, the current document can share cookie information with other pages within the same domain—that is, if the path is set to /thispathname, all pages in /thispathname and all pages in subfolders of /thispathname can access the same cookie information.  注意这句:If you set an expiration date in the past, the cookie is deleted.
      

  4.   

    以下是我做的实验,使用cookie属性,可是实验结果是不成功,
    调用put_cookie时,返回值是正确的,但是再次get_cookie,cookie中的内容并没有变,而且cookie也没有被删掉。    BSTR bstrCookie;    HRESULT hr = E_FAIL;
        CComPtr<IDispatch> spDispDoc;
        hr = m_spBrowser->get_Document(&spDispDoc);
        if (FAILED(hr) || !spDispDoc) return;    CComQIPtr<IHTMLDocument2> spHtmlDoc = spDispDoc;
        if (!spHtmlDoc) return;
        hr = spHtmlDoc->get_cookie(&bstrCookie);
        if (!spHtmlDoc) return;
        CComBSTR bstrExpire;
        CTime ct = CTime::GetCurrentTime();
        bstrExpire = ct.FormatGmt(L"%c");    CComBSTR bstrPut = L"expires=";
        bstrPut += bstrExpire;
        hr = spHtmlDoc->put_cookie(bstrPut);
        if (!spHtmlDoc) return;
        hr = spHtmlDoc->get_cookie(&bstrCookie);
        if (!spHtmlDoc) return;