日期:2014-05-18 浏览次数:21069 次
SHDocVw.WebBrowser webBrowser;//当前浏览器控件 string strFilterKeys="game;sex;stock;hnainfo";//过滤关键字,用;隔开。 private void webBrowser_BeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) { webBrowser.Navigate("http://www.163.com", ref Flags, ref TargetFrameName, ref PostData, ref Headers); string strUrl=URL.ToString(); string[] strFilterKeyItems=this.strFilterKeys.Split(new char[]{';'}); foreach(string strFilterKey in strFilterKeyItems) { if(strUrl.IndexOf(strFilterKey)>-1) { webBrowser.StatusText="未授权访问包含"+strFilterKey+"关键字的地址!"; Cancel=true; return; } } this.webBrowser.StatusText = strUrl; } public int SetSite(object site) { if (site != null) { webBrowser = (SHDocVw.WebBrowser)site; webBrowser.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(webBrowser_BeforeNavigate2); } else { webBrowser.BeforeNavigate2 -= new DWebBrowserEvents2_BeforeNavigate2EventHandler(webBrowser_BeforeNavigate2); } return 0; }