2011-02-24 14 views

risposta

5

Sì, è possibile ora in IE8, anche se non fa parte della struttura di eventi MSHTML, ma Accessibilità.

Trigger (EVENT_OBJECT_REORDER) è una novità in IE8 - Vedere http://blogs.msdn.com/b/ie/archive/2008/12/10/new-accessibility-features-in-ie8.aspx?PageIndex=7

L'usiamo con fuori BHO, ma si potrebbe ugualmente agganciare al di fuori di IE se si sceglie.

BHOClass::BHOClass() 
{ 
if(TrackDHTML) { 
// end event is not used so +1. 
// out of process notifications from accessibility 
    m_eHook = ::SetWinEventHook(EVENT_OBJECT_REORDER, EVENT_OBJECT_REORDER+1, 0, MSAALib_WinEventProc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_OUTOFCONTEXT); 
// in process injecting the dll into IE 
// m_eHook = ::SetWinEventHook(EVENT_OBJECT_REORDER, EVENT_OBJECT_REORDER+1, GetModuleHandle(L"yourhook.dll"), MSAALib_WinEventProc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT); 
} 
} 

Ed ecco come si potrebbe guardare l'accessibilità e ottenere il documento/navigatore

static void CALLBACK MSAALib_WinEventProc(HWINEVENTHOOK hook, 
    DWORD event, 
    HWND hwnd, // this appears to be the hwnd for the tab and not the specific frame 
    LONG idObject, 
    LONG idChild, 
    DWORD dwEventThread, // the thread being watched that triggered this call 
    DWORD dwmsEventTime) 
{ 
if(hwnd != NULL // exclude most mouse move 
    && (OBJID_WINDOW == idObject) // || OBJID_CLIENT == idObject) 
    ) 
{ 
    switch(event) { 
     case EVENT_OBJECT_REORDER: break; 
     case EVENT_OBJECT_SHOW: break; 
     case EVENT_OBJECT_HIDE: break; 
     default: 
      return; 
    } 

    Log(L"Event START - (%ld) object %ld on window(0x%x)%ld thread (0x%x)%ld\n", event, idObject, hwnd, hwnd, dwEventThread, dwEventThread); 
    CComPtr<IAccessible> acc; 
    VARIANT varChild; 
    AccessibleObjectFromEvent(hwnd, idObject, idChild, &acc, &varChild); 
    if(acc) { 
     // step 1 - change from Accessibility interface to html to check we have right type of reorder message 
     CComPtr<IServiceProvider> provider; 
     HRESULT hr = acc->QueryInterface(IID_IServiceProvider,(LPVOID *)&provider); 
     if(SUCCEEDED(hr) && provider){ 
      CComPtr<IHTMLElement> spElement; 
      hr = provider->QueryService(IID_IHTMLElement,IID_IHTMLElement,(LPVOID *)&spElement); 

      if(spElement) { 
       // step 2 - for this doc element get the service provider and then the browser element 
       CComPtr<IServiceProvider> provider2; 
       HRESULT hr = spElement->QueryInterface(IID_IServiceProvider,(LPVOID *)&provider2); 
       CComPtr<IServiceProvider> provider3; 
       if(provider2) 
        hr = provider2->QueryService(SID_STopLevelBrowser,IID_IServiceProvider,(LPVOID *)&provider3); 
       CComPtr<IWebBrowser2> browser; 
       if(provider3) 
        hr = provider3->QueryService(SID_SWebBrowserApp,IID_IWebBrowser2,(LPVOID *)&browser); 

       if(browser) { 
        // step 3 - Do stuff 
       } 
      } 
     } 
    } 
    Log(L"Event DONE - (%ld) object %ld on window(0x%x)%ld thread (0x%x)%ld\n", event, idObject, hwnd, hwnd, dwEventThread, dwEventThread); 
} 
} 
+0

Questo è un po 'tardi, ma c'è un modo per collegare questo evento in JavaScript? – thednp

0

No, ma se si modifica il DOM tramite una libreria di classi come JQuery you can fake the event by yourself.

+0

Non sto cercando di modificare il DOM. Sto cercando di rilevare quando il DOM viene modificato e non tramite JavaScript. Ho MSHTML ospitato in un'applicazione. – GeorgeU

+0

Se il contenitore è in modalità progettazione è possibile utilizzare IMarkupContainer2 :: CreateChangeLog, altrimenti è possibile utilizzare IDispatchEx per sovrascrivere ogni metodo/proprietà di modifica DOM (appendchild, outerhtml, innerhtml, testo, stile, ecc.) Per ogni elemento –

Problemi correlati