2016-07-05 96 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的方法。