C++, web browser control: cannot change encoding/charset

1.2k views Asked by At

There's a document I'm displaying in a web browser ActiveX control hosted in a C++ app. This document has a META tag that specifies incorrect charset, so the output is funny. I know the correct encoding and want to change it programmatically to fix that. But whatever I try, the encoding remains unchanged.

I alredy tried, in various combinations and flavors:

  • IHTMLDocument2::put_Charset (after the document finished loading);
  • changing the "charset" property of the "META" tag (using IHTMLMetaElement);
  • deleting the "META" tag altogether (by setting its "outerHTML" to empty string);
  • refreshing the control.

The control demonstrates remarkable persistence in preserving the incorrect encoding. What are my other options? I can't manipulate the source of the document being loaded.

3

There are 3 answers

1
egrunin On

According to this, it should work if you call IWebBrowser->Refresh() after calling IHTMLDocument2->put_charset().

0
Hervema On

try to put the designMode property "On".

0
user38329 On

Here's what eventually worked:

In the handler of the "NavigateComplete2" browser event,

  • the charset is modified using the charset property,
  • then the META tag is thrown away by setting its outerHTML to empty string,
  • and then the control is refreshed.

Modifying the order of these actions, or omitting a step, will render the entire operation void. MSHTML is picky.