设置& raquo; JavaScript的document.title中的HTML实体? [英] Set » HTML entity in JavaScript's document.title?
问题描述
我使用JavaScript设置 document.title
,我找不到一种方式来提供» (& raquo
),而不显示为文字。
I'm setting document.title
with JavaScript, and I can't find a way to supply » (»
) without it appearing as literal text.
这是我的代码:
document.title = 'Home » site.com';
如果我使用& raquo;在文档的标题标签中,它的作品很好,并正确显示为»但是当我将它包含在 document.title
中时,似乎是无法实现的。
If I use » ; in the title tag of the document it works great and displays correctly as », but it seems to be unescaping when I include it in document.title
.
任何想法?
谢谢!
推荐答案
尝试
document.title = 'Home \u00bb site.com';
一般来说,您可以在这样的网站,然后,一旦知道数字代码,就可以在JavaScript字符串中构造Unicode转义序列。这里,该字符是代码187,它是十六进制中的bb。 JavaScript Unicode转义看起来像\u,后跟4个十六进制数字。
Generally you can look up your special character at a site like this and then, once you know the numeric code, you can construct a Unicode escape sequence in your JavaScript string. Here, that character is code 187, which is "bb" in hex. JavaScript Unicode escapes look like "\u" followed by 4 hex digits.
这篇关于设置& raquo; JavaScript的document.title中的HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!