Modifying HTML-source before displaying it in the browser
-
Hi I hope someone of you is able to solve my problem. What I want to do is to write a plugin for the InternetExplorer (a so called BHO - Browser Helper Object) that will modify the HTML content before InternetExplorer displays the webpage. I already wrote a plugin which will catch the DWebBrowserEvents2::DocumentComplete event. This is my code which works so far:
HRESULT __stdcall CCounter::DocumentComplete(IDispatch* pDisp, VARIANT * URL )
{
ATLTRACE(_T("CCounter::DocumentComplete\n"));return S\_OK;
}
What I now want to do is a bit complicated: Before the browser is about to display the webpage I want to get access and to the document's content and modify it (e.g. for removing keywords previously defined in an external file) I hope someone of you can help me, since it is a question which can't be explained in 1 minute. Thanks in advance regards Gregor
-
Hi I hope someone of you is able to solve my problem. What I want to do is to write a plugin for the InternetExplorer (a so called BHO - Browser Helper Object) that will modify the HTML content before InternetExplorer displays the webpage. I already wrote a plugin which will catch the DWebBrowserEvents2::DocumentComplete event. This is my code which works so far:
HRESULT __stdcall CCounter::DocumentComplete(IDispatch* pDisp, VARIANT * URL )
{
ATLTRACE(_T("CCounter::DocumentComplete\n"));return S\_OK;
}
What I now want to do is a bit complicated: Before the browser is about to display the webpage I want to get access and to the document's content and modify it (e.g. for removing keywords previously defined in an external file) I hope someone of you can help me, since it is a question which can't be explained in 1 minute. Thanks in advance regards Gregor
When the DocumentComplete event is sent, a great deal of rendering is already done. This will not prevent you from modifing the document "on the fly". What I would suggest is the following: 1) QueryInterface pDisp for the IWebBrowser2 interface (or call Invoke directly) 2) Use IWebBrowser2::get_Document to get a pointer to the (Dispinterface of; QueryInterface again) IHTMLDocument2. If the document contains frames you have to find the interface for each frame, and repeat step 3 for each of them. 3) Get the body element and send it to an recursive function that handles each leaf element (gets/puts outer text). It then finds all element children and feed them back to the function. This is just an suggestion, and perhaps someone has a better solution. Sorry if I don´t go into all technical details, but I hope this will help a little. /moliate
-
When the DocumentComplete event is sent, a great deal of rendering is already done. This will not prevent you from modifing the document "on the fly". What I would suggest is the following: 1) QueryInterface pDisp for the IWebBrowser2 interface (or call Invoke directly) 2) Use IWebBrowser2::get_Document to get a pointer to the (Dispinterface of; QueryInterface again) IHTMLDocument2. If the document contains frames you have to find the interface for each frame, and repeat step 3 for each of them. 3) Get the body element and send it to an recursive function that handles each leaf element (gets/puts outer text). It then finds all element children and feed them back to the function. This is just an suggestion, and perhaps someone has a better solution. Sorry if I don´t go into all technical details, but I hope this will help a little. /moliate
As I recall from my prevous experience on close to that issue: DocumentComplete Event may not be always fired... So, check Refresh for example... I recall it didn't work for me... But again, it could be previous versions of WebBrowser... Everything else as rightly described in previous message... GL Igor