1

Long time ago I faced a problem with embedding too much JavaScript inside the html page in <script> tags. The JavaScript had lots of < and > signs and it was somehow conflicting with the actual page html tags.

I am now unable to recreate this. How can this possibly happen? Or are the browsers now a bit more intelligent in handling embedded JavasSript?

Ayman
  • 11,265
  • 16
  • 66
  • 92
  • 1
    You might find http://stackoverflow.com/questions/66837/when-is-a-cdata-section-necessary-within-a-script-tag enlightening (discussion about HTML, XHTML, embedded JavaScript, and CDATA guard). – Amadan Jul 08 '13 at 07:52
  • 1
    No, it was always allowed to use ` – The Alpha Jul 08 '13 at 07:53
  • 3
    @SheikhHeera: He's talking about an error when `` throws syntax error because `<` in `age < 18` is taken as opening of a tag - not the `<` and `>` surrounding `script`. – Amadan Jul 08 '13 at 07:54
  • @Amadan, Oops! Got it wrong! – The Alpha Jul 08 '13 at 07:56
  • In modern browsers, if HTML, `<` within scripts will cause no problem. If XHTML, it will, and needs to be CDATA'd or escaped as `<`. In any case, it's better to externalize scripts. –  Jul 08 '13 at 10:06

1 Answers1

0

I just came across this issue, however, not in a browser , but in an IDE - JBoss Developer Studio (which is a variant of Eclipse IDE)

enter image description here

When i run the application in the browser (its a Java Enterprise application, running on JBoss web server), i get the same error as in the IDE : The content of elements must consist of well-formed character data or markup. While modern browsers have solved this issue, embedding javascript code in a JSF page (Java Server Faces) , as i did, still hits the same problem. Perhaps you might want to give it a try: create a simple JSF application, embed the javascript, run it on a Java web server like JBoss

Newton fan 01
  • 484
  • 5
  • 14