onload event seen only once per tab
-
13-07-2021 - |
문제
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.
제휴하지 않습니다 StackOverflow