I would have expected that the page title respected the charset, but I'm seeing differently. Setting document.title to Fo'o Bar doesn't result in Fo'o Bar being printed as the page title. My browser encoding is set to UTF-8, I am declaring the charset in a meta tag, and the file is saved as UTF-8. It seems like my only option is to use JavaScript to create a DOM node and then set the document.title to the text from that node. Is this right?

有帮助吗?

解决方案

Set your title like this:

document.title = 'Fo\u0027o Bar';

See the MDN for full documentation on escaping Unicode characters.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top