Search code examples
c++dommshtmliwebbrowser2

Why doesn't IWebBrowser2 refresh after a DOM change?


A have a web browser embedded in a dialog of my Win32 C++ application (no MFC, ATL, etc.) and I initially set the document's content from a string containing some HTML code. This HTML is rendered correctly. When the "document complete" event occurs, I manipulate the DOM, e.g. by appending a text node to the BODY element.

The problem is that although calling IHTMLElement::get_outerHTML on the BODY element's interface indicates that the text node is present, the browser content appears unchanged in the dialog.

I have tried calling both IWebBrowser2::Refresh and ::InvalidateRect/::UpdateWindow, but neither helps.

Any ideas? I can post parts of my code if required.

Also, does anyone know

  • whether, in principle, a refresh needs to be somehow triggered after modifying the DOM (or should it be automatic)
  • whether IWebBrowser2::Refresh makes sense when the HTML document was loaded from a string as opposed to a URL

Still hoping for an answer to this one... anyone?


Solution

  • I found the problem - it was a bug in my code. There was a very obscure call to IWebBrowser2::Refresh in the code that was reloading the page, thus reverting my dynamic changes to the DOM.