SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Comments, CSS and Script

    Is there a certain way that you're supposed to denote a page's COMMENTS, the CSS file (linked externally) and the SCRIPT tag (heard that the script tag can cause problems)

    I heard about a CDATA tag or something, but can't find much info on it. If someone knows offhand can you let me know?

  2. #2
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just don't. Link everything. (That is near the bottom of that page btw)

    Douglas
    Hello World

  4. #4
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is recommended (and common practice for HTML (not XHTML) documents) that text contained in a "style" element be enclosed in a comment (<!-- ... --> ) for backward compatibility with pre HTML 3.2 browsers that do not support the "style" element. This prevents them from actually displaying the element's content. For example, use something like <style><!-- ... --></style>.

    About CDATA I can only say, that I tested it with NS 4.7 and they were displayed in the browser. Horrible!
    Therefore I suggest, if you are writing XHTML, do not use all this stuff at all!

    No CDATA and no <!-- -->

    For example for CSS:

    <style type="text/css">
    @import url("global.css" );
    </style>

    or for JavaScript

    <script language="JavaScript" type="text/javascript">
    function back() {
    history.go(-1);
    }
    </script>

    Good luck!

  5. #5
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I would suggest for <script> at least, use CDATA in Javascript comments.

    <script>
    // <![CDATA[
    ....
    // ]]>
    </script>

    As the page you linked to suggests. I don't believe that will be printed by any browser (it shouldn't be).

    However, the safest route is obviously linking to an external file; I only use styles and scripts in the page while designing. Once I'm finished, I move them to external files.
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  6. #6
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Preferably within XHTML it should referenced be externally for XHTML 1.0 Transitional served as text/html then for inline style blocks:

    <script language="JavaScript" type="text/javascript">
    <![CDATA[
    document.write("<b>Hello World!<\/b>" );
    ]]>
    </script>

    Is unlikely to output "Hello World" and just hide the data.

    Hence these interim solutions are generally used, though it would be acceptable to just used the SGML delimiters as was explained.

    Basically I'd use these rules to protect older browsers:

    <script language="JavaScript" type="text/javascript">
    //<![CDATA[
    <!--
    ...JavaScript Character Data...
    //-->
    //]]>
    </script>

    <style type="text/css">
    /*<![CDATA[*/
    <!--
    ...CSS Character Data...
    -->
    /*]]>*/
    </style>
    Last edited by xhtmlcoder; Sep 16, 2003 at 07:13.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •