C # WebBrowser clears the current Web site cookie

Source: Internet
Author: User

?
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")

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.