JavaScript entity (Pitfall)

This functionality is deprecated and should not be used in new projects.

The HTML character entities are useful for describing hard to type characters.

They are functionally similar to the back-quote substitutions that are available server-side with Netscape Enterprise Server.

MSIE version 3.0 introduced a means of passing JavaScript values into the HTML source space using a syntax that is similar to the character entity syntax. However, it is used in contexts that character entities were never intended to be used in. It is also advised as deprecated functionality in the HTML version 4.0 standard.

You might indicate an image width like this:

<IMG SRC="..." WIDTH="100">

The value for the image width can be taken from a JavaScript expression like this:

<IMG SRC="..." WIDTH="&{myWidth * myScaleFactor};">

This assumes that the values myWidth and myScaleFactor have already been defined in some earlier fragment of JavaScript.

The entity can be used to replace a single character in the tag attribute value so you can concatenate other characters such as percent signs if you use it in <HR> tags for example.

This functionality should be avoided and the usual client or server methods used to define the values in HTML tags.

Example code:

   <HTML>
   <BODY>
   <FORM>
   <INPUT TYPE="text" VALUE="&{top.name;}">
   </FORM>
   </BODY>
   </HTML>

See also:Adding JavaScript to HTML, Backquote (`), Deprecated functionality, Pitfalls

Cross-references:

Wrox Instant JavaScript - page - 47