11

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?

Dabbler
  • 9,733
  • 5
  • 41
  • 64
  • Refresh should be automatic. Are you working in an STA thread, and are you pumping Windows messages? http://stackoverflow.com/questions/2222365/what-is-a-message-pump – Simon Mourier Jan 06 '16 at 09:26

2 Answers2

0

You should test it using a static content eg

<html>
<head></head>
<body>
Hello World
<script>
alert("a");
</script>
</body>
</html>

If the alert box shown but without anything,this mark you implemention has problem.

杨家俊
  • 1
  • 2
-2

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.

Dabbler
  • 9,733
  • 5
  • 41
  • 64