-1

I have just started leaning javascript.

I am just wondering why

<HTML>
<HEAD>
    <TITLE>Javascript entities</TITLE>
    <SCRIPT LANGUAGE = "JavaScript">
        var fontSize = "10"
        var fontColor =  "#0000FF"
    </SCRIPT>
</HEAD>
<BODY>
    <FONT COLOR = "{fontColor};" SIZE = "&{fontSize};">
    flexible attributes with javascript entities ;
    </FONT>
</BODY>
</HTML>

i get the tiny text about entities in yellow instead of blue. And when I change the fontColor to for example "&red" it is green. When I just leave fontColor empty (" ") it is green too..

I am using firefox under linux. Thanks for help!

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Nikolskyy
  • 51
  • 2
  • 7
  • you don't need the `language= "javascript"` attribute; that's by default. – SuperStormer Jun 12 '17 at 00:00
  • 5
    Your HTML and its attributes and overall usage is obsolete. You need to find a better tutorial or read the HTML specification: https://developers.whatwg.org/ – Rob Jun 12 '17 at 00:13
  • 2
    Mostly answered by [Why does HTML think “chucknorris” is a color?](https://stackoverflow.com/questions/8318911/why-does-html-think-chucknorris-is-a-color) - `"{fontColor};"` and `"&red"` are not valid color attribute values. Also note the learning material you are using is _seriously out of date and should not be used_. `` tags have been deprecated for quite some time now. – traktor Jun 12 '17 at 00:16
  • 3
    @Traktor53 `` is obsolete, not just deprecated: https://developers.whatwg.org/obsolete.html#obsolete – Rob Jun 12 '17 at 00:17
  • 1
    @SuperStormer—the language attribute for script elements was deprecated in HTML 4 and removed in later versions. It's the *type* attribute that defaults to *text/javascript*. – RobG Jun 12 '17 at 00:38
  • Where did you get the idea that you can write things like `{fontColor}` or `&{fontSize}` to pick up their values from JS variables? –  Jun 12 '17 at 01:33
  • Apparently javascript entities as you've demonstrated were supported on Netscape 4 and IE6. As far as I know they aren't supported on modern browsers – Brian Jun 12 '17 at 02:50
  • Thanks a lot! As mentioned I just took a random javascript book (Chuck Easttom - Advanced Javascript) and started working n it. It is quite old. Thanks for the interesting Chuck Norris - article – Nikolskyy Jun 12 '17 at 15:23

2 Answers2

0

The tutorial exercise posted closely matches one in Learn Advanced JavaScript Programming in its section on JavaScript Entities. The server the e-book appears on seems to be an archive of material of historical interest that perhaps should not, and in some cases can not, be applied to the modern web.

In fact this particular book was written for programming HTML in Netsape Navigator 4. Use of JavaScript entities in HTML attributes was also described in Netscape's Javascript client-side guide for JavaScript 1.3, from 1998.

JavaScript Entities, and layer objects introduced by Netscape 4, are obsolete technologies and no longer supported. The books describing them date from last century, before the HTML DOM started to become standardized, and should not be used to learn about current web technnology.

traktor
  • 17,588
  • 4
  • 32
  • 53
0

As Traktor53 said, JavaScript entities (or "script macros") are an old syntax defined in the HTML 4.01 specification but never implemented by all major browsers (except Netscape).

I should add to this that not long ago I wrote a small polyfill, JSEntities, that implements JavaScript Entities in modern HTML5.

madmurphy
  • 1,451
  • 11
  • 20