Javascript - avoid character entity (β†’ displayed as & rarr;)

document.title = ("hello → goodbye"); 

This does not display the arrow: "β†’" as it should. How to avoid this so that he does it?

+4
source share
3 answers

You do not need to avoid this at all.

Just write

 document.title = "hello β†’ goodbye"; 

(and make sure your file is UTF8)

If you really want to avoid this, you can use the Javsacript escape code: "\u2192"

Objects are used only in the HTML source; you cannot use them in regular strings. (Except innerHTML , which is the source of HTML)

+8
source

You need to use the escape sequence of JavaScript characters \u2192 :

 document.title = "hello \u2192 goodbye"; 

Or, as SLaks indicates , if the JavaScript file is in Unicode, you can put it directly in the code:

 document.title = ("hello β†’ goodbye"); 
+5
source

I don’t believe that the HTML <title> allows markup at all, it just treats everything as a string literal. In other words, don't try to use HTML objects in your script, just use the actual "β†’" character.

+2
source

Source: https://habr.com/ru/post/1346560/


All Articles