如何在 WPF 中的 Web 浏览器控件中显示 unicode 字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19315078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to display unicode character in web browser control in WPF
提问by Sandip
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 ?
我必须在网络浏览器控件中设置任何设置吗?
采纳答案by noseratio
You did not tell us how your load the content into WebBrowser. If you navigate to a URL, make sure the server sends correct charsetencoding as part of Content-Typein HTTP response headers:
您没有告诉我们您如何将内容加载到WebBrowser. 如果您导航到一个 URL,请确保服务器发送正确的charset编码作为Content-TypeHTTP 响应标头的一部分:
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.charsetproperty, once the document has been loaded. This property is not exposed by the WPF version of WebBrowser, so you'd need to use dynamic:
如果您无法控制服务器,并且服务器没有在响应内容中指定字符集(一种不好的方式),则在加载文档后,您需要使用 DOM document.charset属性手动设置编码. 的 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. Load the page into full IE, go to View/Encoding/More menu and find what works for that page.
我在这里使用“Windows-1252”作为示例,如果服务器没有指定它,您实际上需要尝试为特定网页找到正确的值。将页面加载到完整的 IE 中,转到查看/编码/更多菜单并找到适合该页面的内容。
That said, if you navigate to a string (with NavigateToString), it should support Unicode characters out-of-the-box.
也就是说,如果您导航到一个字符串(使用NavigateToString),它应该支持开箱即用的 Unicode 字符。
回答by Rajesh Subramanian
You can try changing the header by adding Accept-Languagein Navigate method.
您可以尝试通过添加Accept-LanguageNavigate 方法来更改标题。
http://support.microsoft.com/kb/172998
http://support.microsoft.com/kb/172998
SO Link
SO链接

