how to display unicode character in web browser control in WPF

夙愿已清 提交于 2019-12-22 18:11:15

问题


I want to display unicode character for different languages in web browser control of WPF but it displays special characters

is there any setting I have to set in web browser control ?


回答1:


You did not tell us how your load the content into WebBrowser. If you navigate to a URL, make sure the server sends correct charset encoding as part of Content-Typein HTTP response headers:

Content-Type: text/html; charset=utf-8

If you have no control over the server, and the server doesn't specify the charset in the response content (a bad manner), you'd need to manually set the encoding using DOM document.charset property, once the document has been loaded. This property is not exposed by the WPF version of WebBrowser, so you'd need to use dynamic:

dynamic domDocument = webBrowser.Document;
domDocument.charset = "Windows-1252";

I'm using "Windows-1252" as an example here, you'd actually need to experiment to find the correct value for a particular web page, if the server doesn't specify it. Load the page into full IE, go to View/Encoding/More menu and find what works for that page.

That said, if you navigate to a string (with NavigateToString), it should support Unicode characters out-of-the-box.




回答2:


You can try changing the header by adding Accept-Language in Navigate method.

http://support.microsoft.com/kb/172998

SO Link

How to set Accept and Accept-Language header fields?



来源:https://stackoverflow.com/questions/19315078/how-to-display-unicode-character-in-web-browser-control-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!