Reputation: 5652
I want to include a JavaScript (.js) file on my page. In the JavaScript I have a statement similar to as follows:
document.title = "Site › Page";
The problem is, ›
doesn't do the trick. It doesn't get parsed as an HTML entity, and the browser's title bar displays "Site › Page"
.
I tried using the actual character, e.g.
document.title = "Site › Page";
But that comes up with the question mark symbol in Firefox because it is unencoded.
Any suggestions?
Upvotes: 1
Views: 885
Reputation: 5652
I found the solution. I was editing the external .js file with Notepad and the encoding defaults to ANSI. When I resave the the file with UTF-8 encoding, the character set includes my character, and it outputs correctly.
Thank you for your responses!
Upvotes: 0
Reputation: 51668
When you set HTML properties using JavaScript, you shouldn't HTML-encode them. But if you include the characters directly in your JavaScript string, then the encoding of your source code file may affect how they're interpreted. It's safer to use escape sequences in your strings, like this:
document.title = "Site \u203A Page";
That will use the Unicode code 203A (in hexidecimal), which is 8250 in decimal, which I believe is the character you're looking for.
Upvotes: 2
Reputation: 647
Hmm.. I can't seem to recreate the problem.
I'm using the text in a simple html document with the javascript inline, and it displays the character '>' just fine in the title bar of firefox. the following works for me:
<script type="text/javascript">
document.title = "Site › Page"
</script>
Maybe try the script tag inline to see if that works, and if so you have at least narrowed down the problem to some kind of linking issue.
Upvotes: 0