Why doesn't IWebBrowser2 refresh after a DOM change?
Asked Answered
S

2

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?

Shaper answered 17/1, 2015 at 11:55 Comment(1)
Refresh should be automatic. Are you working in an STA thread, and are you pumping Windows messages? https://mcmap.net/q/94605/-what-is-a-message-pumpBusty
S
-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.

Shaper answered 6/1, 2016 at 12:24 Comment(0)
N
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.

Nolannolana answered 28/2, 2015 at 3:47 Comment(0)
S
-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.

Shaper answered 6/1, 2016 at 12:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.