如何在浏览器标题中添加 Unicode
我想在 IE 的标题栏(和选项卡)中放置 unicode 字符。
如何使用 C# 实现此目的?
I would like to put unicode characters in IE's title bar (and tabs).
How do I achieve this using C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
设置 Page.Title 对我来说效果很好,假设您使用的是支持 Unicode 的响应编码(例如默认的 UTF-8)。
您想要设置的角色到底是什么?请记住,页面标题是使用操作系统的窗口标题栏字体呈现的,而不是为页面 HTML 内容设置的字体,因此可用于“标题”的字符范围可能比用于页面内容的字符范围要小。如果您选择的字符不存在于标题栏使用的字体中,您可能会得到正方形。
(对于其他操作系统呈现的元素也可能会发生同样的情况,例如某些浏览器中的选择菜单。)
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.)
标准方法是按如下方式对 unicode 字符串进行编码:
但是,HTML 的</code> 标记作为输入的内容相当严格。例如,您不能在其中添加更多 HTML。
HtmlEncode 使用的标准编码器的编码能力显然也存在限制,因此您的情况可能会有所不同。
The standard way would be to encode your unicode string as follows:
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.
你所说的“unicode字符”是什么意思?
如果我有一个带有 html 的 UTF-8 文件,我可以将其放入其中并正确显示:
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:
假设您使用的是 ASP.Net,您可以在 web.config 中将站点上所有页面的响应编码设置为 UTF-8,如下所示:
完成此操作后,将任何有效的 Unicode 字符串分配给 Page.Title 应该会产生预期的结果。当然,您也可以使用其他 Unicode 编码,但 UTF-8 是最常见的。
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:
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.