سؤال

I have a BHO which listen for the onload event. here is the code (simplified) run at each BeforeNavigate2 event:

CComQIPtr<IWebBrowser2> pBrowser(pDisp);

CComPtr<IDispatch> pUnk = NULL;
HRESULT hr = pBrowser->get_Document(&pUnk);

CComQIPtr<IHTMLDocument2> pHtmlDoc2(pUnk);

CComQIPtr<IHTMLWindow2> pWindow2;
pHtmlDoc2->get_parentWindow((IHTMLWindow2**) &pWindow2);

CComQIPtr<IHTMLWindow3> pWindow3(pWindow2);

VARIANT_BOOL result = VARIANT_TRUE;
CComBSTR onEvent(TEXT("onload"));
pDomEvent = new Page::DOMLoaded();

pWindow3->attachEvent(onEvent, pDomEvent, &result);

(I've removed all the checks to simplify)

The onload event is triggered for the first page, but not for the pages visited afterwards. I could not find out what I'm missing, or doing wrong.

هل كانت مفيدة؟

المحلول

BeforeNavigate is probably too early to do this. On the second and subsequent calls I suspect you are working with the old window. Try NavigateComplete2 instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top