Triyng to write BHO to inject an iFrame into every web page the user visits using different listeners, causes a loop and the absence of an iframe

Unfortunately, I am stuck writing a BHO for Internet Explorer. Its function is to introduce an iframe into every web page the user visits, displaying some (relatively) constant information when the user goes about his business. I managed to inject through the pretty hacker series mshtml cast, as follows, where Explorer is a WebBrowserClass object and foo.html is supplied with a BHO source:

IHTMLDocument2 document = (IHTMLDocument2) Explorer.Document;
IHTMLDocument3 doc3 = (IHTMLDocument3)document;
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "foo.html");
iframe.setAttribute("id", "iFrame");
iframe.setAttribute("style", "position: fixed; left: 0px; top: 0px; border: 0px; width: 100%; height: 45px; background-color: white");
IHTMLElementCollection iec = doc3.getElementsByTagName("body");
IHTMLElement elem = (IHTMLElement)iec.item(0);
IHTMLDOMNode domnode = (IHTMLDOMNode)elem;
domnode.appendChild((IHTMLDOMNode)iframe);

It works! I think. Like. It causes an infinite loop if I insert it into OnDocumentComplete and it does not display an iframe anyway. The loop problem is using Explorer event listeners, such as OnDocumentComplete, because they are called whenever the page inside the iFrame finishes loading, which then calls the injection function, which then calls OnDocumentComplete, which ... well, you get this idea. I tried using OnNavigateComplete, but it still loads several times on pages downloaded from multiple sources (for example, google search main page with autocomplete turned on.) But even if it doesn't go into an infinite loop, I still don't see a visible iframe .

, , : 1) iframe? ( javascript)... 2) iframe , , BHO ?

:

void OnNavigateComplete(object pDisp, ref object URL)
{
  if ((_currentDocument != null) && (isValidURL(_currentDocument.url))) 
  {
      injectFrame();
  }
}

void OnDocumentComplete(object pDisp, ref object URL)
{
    if (Explorer.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
    {
        _currentDocument = Explorer.Document as mshtml.HTMLDocument;
        if (_currentDocument != null)
        {
            //injectFrame();
        }
    }
}
+3
1

, , . OnDocumentComplete , ... , iframe , .

, , URL- OnDocumentComplete:

void OnDocumentComplete(object pDisp, ref object URL)
{
  // _currentDocument = Explorer.Document as mshtml.HTMLDocumentClass;
    if (Explorer.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
    {
        _currentDocument = Explorer.Document as mshtml.HTMLDocument;
        if (_currentDocument != null)
        {
            // we have a document - attach our events
            // on onload event should go here if the document is now complete...
            if (!URL.Equals("http://url.to/foo.html")) injectFrame();
        }
        else
        {
            // document is null?
            // Debugger.ShowMessage("Tried to attach to document, but was null");
        }
    }
}

iframe, Style, -, , OTHER. , - ...

setAttribute("style","position: fixed; left: 0px; top: 0px; border: 0px; width: 100%; height: 45px; background-color: white");

iframe.style.setAttribute("position", "fixed");
iframe.style.left="0px";
iframe.style.top="0px";
iframe.style.border="0px";
iframe.style.width = "100%";
iframe.style.height="45px";
iframe.style.backgroundColor="white";

, , .

+2

All Articles