I have a requirement to listen to post message from dynamic HTML page post when forms web browser control navigation is done.
The dynamic page sends JSON data through Window.Parent.PostMessage(JSON data )
We can't use iframe to load the dynamic page and hook message listener.
I tried below code to hook onemessage event .
I chose not to use DocumentCompleted event to hook onmessage handler since it is fired when doc is completed and there is no point in adding event handler for onmessage event to listen post messages as the message is posted and window does not have handler attached.
void_loginBrowser_Navigated(objectsender,WebBrowserNavigatedEventArgse)
{
vardoc = (senderasSystem.Windows.Forms.WebBrowser).Document;
mshtml.
IHTMLWindow3rawWindow = (mshtml.IHTMLWindow3)doc.Window.DomWindow;
rawWindow.attachEvent("onmessage",new DHTMLEventDelegate(MyEventHandler));
}
public delegate void DHTMLEventDelegate(IHTMLEventObj e);
public void MyEventHandler(IHTMLEventObj e)
{
//this is not firing
}
I don't seem to resolve IHTMLEventObj5(which MSDN says will contain message data) even though I have MSHTML.dll ver 10.0 .
Please help me in attaching this event as I need to receive the JSON data through this event only .
(this.YourEventHandler)
}
//doc.DomDocument
mshtml.
IHTMLWindow3rawWindow = (mshtml.IHTMLWindow3)doc.Window.DomWindow;
// rawWindow.attachEvent("onmessage", OnLoadListener);
rawWindow.attachEvent(
"onmessage",newDHTMLEventDelegate(this.YourEventHandler));