문제

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