【问题标题】:BHO OnDocumentComplete for the top frame only?BHO OnDocumentComplete 仅适用于顶部框架?
【发布时间】:2014-01-28 13:13:29
【问题描述】:

我正在 CSHARP 中开发 BHO,但在 onDocumentComplete 方法中遇到问题。
它在主文档加载的每个 IFRAME 上运行。我怎样才能避免它?我只想处理主窗口中的事件。

public void OnDocumentComplete(object pDisp, ref object URL)
  {
      document = (HTMLDocument)webBrowser.Document;    
      document.body.style.backgroundColor = "red";
  }

【问题讨论】:

    标签: c# iframe bho


    【解决方案1】:

    this.sitepDisp 进行比较。如果它们相等,则代码在主框架中运行:

    public void OnDocumentComplete(object pDisp, ref object URL)
    {
        if (pDisp != this.site) {
            // Ignore subframes
            return;
        }
        document = (HTMLDocument)webBrowser.Document;    
        document.body.style.backgroundColor = "red";
    } 
    

    【讨论】:

    • this.site 是什么?我收到错误消息,我的项目不包含“站点”的定义,并且找不到接受“Greyhound.BHO.BHO”类型的第一个参数的扩展方法“站点”(您是否缺少 using 指令或程序集引用?)
    • @user280109 您的 SetSite 方法(实现 IObjectWithSite 接口)在站点更改时接收的对象。
    • 我是 C# 新手,我在 setsite 方法中看到了站点对象,但我无法从 ondocumentcomplete 方法访问它。我需要以某种方式使变量成为全局变量吗?
    • @user280109 您已将其存储为类实例的成员。
    猜你喜欢
    • 1970-01-01
    • 2010-10-22
    • 2019-11-15
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 2014-07-31
    • 2022-01-22
    • 1970-01-01
    相关资源
    最近更新 更多