2016-07-05 99 views
1

我已經實現BHO插件來檢測使用C#的網頁上的NUMBER。每次頁面加載在網頁中追加JavaScript,並檢測到javascript檢測數字,並用超鏈接數字代替它。BHO插件不能正常工作

代碼

public void WebBrowser_DownloadComplete() 
{ 
HTMLDocument document = (HTMLDocument)webBrowser.Document; 

    IHTMLElement head = (IHTMLElement)((IHTMLElementCollection) 
          document.all.tags("head")).item(null, 0); 
    IHTMLScriptElement scriptObject = 
     (IHTMLScriptElement)document.createElement("script"); 
    scriptObject.type = @"text/javascript"; 
    scriptObject.src = @"myscript.js"; 
((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptObject); 


} 

問題

當我與離線網頁,它正在精測插件。但在線頁面不起作用。 DownloadComplete事件會多次觸發。

問題

哪個事件是由IE瀏覽器時,網頁是刷新並加載觸發?

回答

4

你必須在DocumentLoaded事件中添加條件如下圖所示,

if (rootDocLoaded && (HTMLDocument != null) && url != "about:blank"){ 
    //Your code here 
} 

使用上述條件的稱爲加載整個頁面只有一個後。你也可以使用beforeNavigateNavigate的方法。