c# webbrowser 清除當前網站 cookie

來源:互聯網
上載者:User

標籤:blog   class   code   java   int   get   

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16         //這個方法可以建立一個清除當前頁面下指定域的所有cookie         //必須是可以訪問的域,比如你訪問的是qq.com,那麼可以清除www.qq.com,qzone.qq.com等頁面的cookie         //但是不能清除baidu.com這樣的cookie. 明白嗎? 不是一個域下的是無法清除的         public string GetClearCookieJs(string domain)         {             return "function delallcookie(domain){var cv=document.cookie.split(‘; ‘);var temp;for(var i=0;i<cv.length;i++){temp=cv[i].split(‘=‘);document.cookie=temp[0]+‘=;‘+((domain)?‘domain=‘+domain+‘;‘:‘‘)+‘expires=Thu, 01-Jan-1999 00:00:01 GMT;‘}} delallcookie(‘" + domain + "‘);";         }   //下面展示如何調用 using mshtml;//這個using 需要從項目中添加引用Microsoft.mshtml //C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll //webBrowser1載入完成後,使用下面的語句,可以清除qq.com域下的所有cookie //前提是,你必須訪問的是qq.com.如果你訪問的不是qq.com,是無法清除qq.com域下的cookie的   HTMLDocument doc = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument; doc.parentWindow.execScript(GetClearCookieJs("qq.com"), "javascript")

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.