Set » HTML entity in JavaScript's document.title?

别说谁变了你拦得住时间么 提交于 2019-12-03 02:30:34

Try

document.title = 'Home \u00bb site.com';

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.

Javascript does not use HTML entities.

You should simply use the actual » character in your string, and make sure that the file is saved and sent as UTF8.

document.title takes the string as it is, so you can do this:

document.title = 'Home » site.com';

If you need to provide it as the entity name, you can set the innerHTML attribute. Here are two examples of how you can do it.

document.getElementsByTagName('title')[0].innerHTML = '»';
// or
document.querySelector('title').innerHTML = "»";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!