PDA

View Full Version : Entity Codes in JavaScript Menu Items Text Array



NeilWeston
06-14-2006, 02:26 AM
I have used HV Menu for months and find it great. - Please don't stop reading cos of "HV Menu", as it may be just a general JavaScript Array problem.

The problem now is that I need to add some International Fonts to the Menu Items. Specifically, the lowercase diaeresis/umlaut (ü or ) and the lowercase German sz (ß or ).

I have tried the following;

1. Hard coding the characters straight off the keyboard, but this does not render in the menu on the web page.

2. Using the above codes within the text, but it seems that because the codes are between the text quotations, it is the codes themselves that are rendering not the character. ie "Softstone Wei&#223", so what u c is what u get. (This is how I have left it.)

3. Breaking the menu text, ie "Softstone Wei"&#223, and "Softstone Wei"+&#223, even "Softstone Wei"+"&#223", but all of these make the script fall over. Even though it is all within the comma separator for the Menu Text string in the Menu Array.

Can anybody assist on how I can get these codes to render as the correct characters in the Menu.

Thank you.

- Neil

The URL to the Site is: http://www.slatestone.com.au

The Menu Items affected are; GranitiFiandre/porcelaingres/grestach/softstone/ and GranitiFiandre/porcelaingres/grestach/slate/

The errors will be pretty obvious in each menu item.

PS: I have purposefully left the ";" off the end of each entity code in this thread so that it does not render, but I have included it in the script. - Neil

jscheuer1
06-14-2006, 04:33 AM
I tried the hex code (javascript strings escaped hex codes). It may depend (to a degree) upon your server and your charset as declared in this sort of meta tag:


<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

But, if all that is lined up right (if the named entities work in regular text, it probably is), these both worked locally in three browsers so, should do the job.


"softstone wei\xdf"

and:


"slate gr\xfcn-schwarz"

The way this works is that you use the \x prefix and then the two 'digit' hex value of the desired character.

Others, more knowledgeable than I, would know the precise terms for all of these things and if there are any pitfalls to this approach but, it should be serviceable for most of your target audience.

NeilWeston
06-14-2006, 04:49 AM
Thanks John, works perfectly, have checked it on both Mac & Windoze browsers - very much appreciated.

- Neil

mwinter
06-14-2006, 04:21 PM
Please don't stop reading cos of "HV Menu", as it may be just a general JavaScript Array problem.No. This is a 'including markup in script code' problem. :)


1. Hard coding the characters straight off the keyboard, but this does not render in the menu on the web page.As you haven't provided an example of your attempt at this, it's not possible to give a precise reason. However, it could well be a character encoding problem.


2. Using the above codes within the text,They're called entity references. The similar markup that consists of decimal or hexadecimal numbers (for example, &#38;#160; or &#38;#xa0;; both are the same as &nbsp&#59;) are called character references.


but it seems that because the codes are between the text quotations, it is the codes themselves that are rendering not the character.No, it's because they are in a script element. The contents of script and style elements are the SGML type CDATA; character data. Unlike PCDATA (parsed CDATA), the contents of these elements aren't scanned for markup (only the closing tag). As a result, everything is passed as-is to the script interpreter.

There are, what would seem to be, exceptions to this: the write and writeln methods of the document object, and the innerHTML property of element objects. Using any of these with strings containing markup, including entity and character references, will act as you might expect: inserting the corresponding markup. This is because those strings will be passed back through a markup parser before being added into the document tree. Using a DOM method like createTextNode will treat the strings as literal text.



I tried the hex code (javascript strings escaped hex codes).The other alternative is Unicode character escape sequences. These are of the form \uXXXX where each X is a hexadecimal number for the Unicode codepoint of that character. Leading zeros are required if the number has less than four digits. If the character is in the upper Unicode range, the character needs to be written as a surrogate pair: essentially, writing UTF-16 with escape sequences.

Mike

NeilWeston
06-14-2006, 09:31 PM
Thanks Mike, that clarifies things - I think ;-)

I had thought of escape characters and tried the \ and also read % somewhere but obviously to no avail.

Also I have only seen the &#000 and &szlig; type of Characters previously so both you and John have opened up whole new areas for me to play in.

Thanks again guys, and I am just glad the the frustrations of yesterday morning are over and all seems to be working well now with the Menu and the use of the characters on the Site Map as well.

Cheers,

- Neil