• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding CDATA tag in script tag

 
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, I am using below code to prevent script tag validation parsing.
I am using is correctly.



Is there any mistake please let me know
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what happen guys? Nobody wants to answer my question. Please reply.
 
author
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're using XHTML, then strictly I guess the CDATA blocks are required. But really, none of this is needed in practice. The comment will probably trick the validator, but unless you're targeting Netscape 2.0 I don't think you actually need them. In any case, a better approach would be to use external scripts, which will clean up your page, and help with front-end performance.
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Johansen wrote:If you're using XHTML, then strictly I guess the CDATA blocks are required. But really, none of this is needed in practice. The comment will probably trick the validator, but unless you're targeting Netscape 2.0 I don't think you actually need them. In any case, a better approach would be to use external scripts, which will clean up your page, and help with front-end performance.




Thanks for replying....

But can you tell me if i was right(see code above)
 
Christian Johansen
author
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, yes, it will work but it is not needed.
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Johansen wrote:Well, yes, it will work but it is not needed.



But i have seen this code which is different from my code please see it.




 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you run your code through a validator? What does it say?

Eric
 
Christian Johansen
author
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was actually a bit quick in my first reply. Your second example is the right one if you need the HTML comments. You really don't, unless you're prepared to support 10+ year old browsers. Also the whole CDATA thing only matters if your site is actually served as XHTML (i.e., with a Content-Type of "application/xhtml+xml"). I doubt you are doing this, as for example Internet Explorer does not support it at all until the upcoming version 9.

Here's the simplest way (I think) to trick the validator and be safe in browsers:

 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Johansen wrote:I was actually a bit quick in my first reply. Your second example is the right one if you need the HTML comments. You really don't, unless you're prepared to support 10+ year old browsers. Also the whole CDATA thing only matters if your site is actually served as XHTML (i.e., with a Content-Type of "application/xhtml+xml"). I doubt you are doing this, as for example Internet Explorer does not support it at all until the upcoming version 9.

Here's the simplest way (I think) to trick the validator and be safe in browsers:




What if multi-line comments are not supported. I think you are incorrect. Please check your code and can you explain it.
 
Christian Johansen
author
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What browser doesn't support multi-line comments?
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Johansen wrote:What browser doesn't support multi-line comments?



how would you hide the javascript code from really old browser which don't understand javascript.
 
Christian Johansen
author
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I've already said, doing so isn't necessary. But if you absolutely want to, your second example will work. However, keep in mind that if you're using a JavaScript library such as jQuery, your code will break in old browsers anyway. Not in those archaic browsers that don't support JavaScript at all, but slightly newer browsers such as IE 5.5. So unless you're including some very basic JavaScript, chances are that the comments will protect your site from crashing in e.g. Netscape 2, but the site will still (probably) fail in Firefox 1, IE 5.5, Safari 2 and others, for other reasons.
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Johansen wrote:As I've already said, doing so isn't necessary. But if you absolutely want to, your second example will work. However, keep in mind that if you're using a JavaScript library such as jQuery, your code will break in old browsers anyway. Not in those archaic browsers that don't support JavaScript at all, but slightly newer browsers such as IE 5.5. So unless you're including some very basic JavaScript, chances are that the comments will protect your site from crashing in e.g. Netscape 2, but the site will still (probably) fail in Firefox 1, IE 5.5, Safari 2 and others, for other reasons.



Actually i have to incorporate all the browsers. You are right today that is not neccessary. But i want to do it as an learning exercise. Can you explain how commenting works in following code


It will be great help.
reply
    Bookmark Topic Watch Topic
  • New Topic