Accessing document in HTML Window onbeforeunload event handler

  • Thread starter Thread starter Invalid
  • Start date Start date
I

Invalid

I'm capturing the onbeforeunload event as shown below. However,
IHTMLEventObj e contains no usefull information regarding the
window (and thus document object) associated with the event. I'm
trying to gain access to document.activeElement.

Can that be done by casting e to some other interface? Would I buy
something by setting the window.onbeforeunload property rather
than window.HTMLWindowEvents2_Event_onbeforeunload? I'm
not quite sure what the difference is between those two approaches,
but I have been able to capture events via the later but not the former.
Any advice would be appreciated.


public void HookOnBeforeUnload(HTMLDocumentClass document)
{
HTMLWindow2Class window = (HTMLWindow2Class)document.parentWindow;
window.HTMLWindowEvents2_Event_onbeforeunload +=
new HTMLWindowEvents2_onbeforeunloadEventHandler(window_HTMLWindowEvents2_Event_onbeforeunload);
}

public void window_HTMLWindowEvents2_Event_onbeforeunload(IHTMLEventObj e)
{
Debug.Write("OnBeforeUnload\n");
}
 
Back
Top