1

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?

2
  • 1
    Please don't use Unicode art. That character is a closing quotation character, not an arrow. Commented Feb 27, 2011 at 0:07
  • It works with chrome...I'm guessing it's a browser problem... Commented Feb 27, 2011 at 1:12

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is also a valid way to do it. Thanks for your input!
0

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.

1 Comment

It works fine inline because the encoding of the HTML page is specified as UTF-8.
0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.