I would like to put unicode characters in IE's title bar (and tabs).
How do I achieve this using C#?开发者_如何学Go
Page.Title = "//someunicode//"
does not work
Setting Page.Title works fine for me, assuming you're using a Unicode-capable response encoding such as the default UTF-8.
What are the characters you are trying to set exactly? Bear in mind that the page title is rendered using the operating system's window title bar font, and not the fonts set up for page HTML content, so you may have a smaller range of characters available for Title than you do for page content. If you choose characters that don't exist in the font used for title bars you may get squares.
(The same may occur for other OS-rendered elements, for example select menus in some browsers.)
The standard way would be to encode your unicode string as follows:
Page.Title = System.Web.HttpUtility.HtmlEncode("<some unicode />");
However the <title>
tags of HTML are fairly rigid in what they take as an input. You can't for example put any more HTML in them.
There are also apparently limitations in what the standard Encoder used by HtmlEncode is capable of encoding so your mileage may vary.
What do you mean by "unicode characters"?
If I have a UTF-8 file with html, I can put this in it and it displays correctly:
<title>HTML test. TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚N̐Y̡ </title>
Assuming you're using ASP.Net, you can set the response encoding of all pages on your site to UTF-8 in web.config as follows:
<configuration>
<system.web>
<globalization
responseEncoding="utf-8"
/>
</system.web>
</configuration>
Once you've done this, assigning any valid Unicode string to Page.Title should produce the expected result. You can of course also use other Unicode encodings, but UTF-8 is the most common.
精彩评论