简体   繁体   English

如何在WPF中的Web浏览器控件中显示Unicode字符

[英]how to display unicode character in web browser control in WPF

I want to display unicode character for different languages in web browser control of WPF but it displays special characters 我想在WPF的Web浏览器控件中显示不同语言的unicode字符,但它显示特殊字符

is there any setting I have to set in web browser control ? 我必须在Web浏览器控件中进行任何设置吗?

You did not tell us how your load the content into WebBrowser . 您没有告诉我们如何将内容加载到WebBrowser If you navigate to a URL, make sure the server sends correct charset encoding as part of Content-Type in HTTP response headers: 如果导航到URL,请确保服务器在HTTP响应标头中发送正确的charset编码作为Content-Type一部分:

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. 如果您无法控制服务器,并且服务器未在响应内容中指定字符集(一种不好的方式),则在文档加载后,您需要使用DOM document.charset属性手动设置编码。 This property is not exposed by the WPF version of WebBrowser , so you'd need to use dynamic : WPF版本的WebBrowser不会公开此属性,因此您需要使用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. 我在这里以“ Windows-1252”为例,如果服务器未指定,则实际上您需要尝试为特定的网页找到正确的值。 Load the page into full IE, go to View/Encoding/More menu and find what works for that page. 将页面加载到完整的IE中,转到“查看/编码/更多”菜单,然后找到适用于该页面的内容。

That said, if you navigate to a string (with NavigateToString ), it should support Unicode characters out-of-the-box. 也就是说,如果您导航到一个字符串(使用NavigateToString ),则该字符串应立即支持Unicode字符。

You can try changing the header by adding Accept-Language in Navigate method. 您可以尝试通过在Navigate方法中添加Accept-Language来更改标头。

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

SO Link SO链接

How to set Accept and Accept-Language header fields? 如何设置Accept和Accept-Language标头字段?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM