W3C html validator flags error in javascript

Discussion in 'HTML' started by xyZed, Mar 25, 2006.

  1. xyZed

    xyZed Guest

    Although related to false javascript errors during validation checks,
    this is a question about html validation.

    I have several affiliate links stopping my pages validating. They use
    javascript which I don't understand. Apparently it's a known issue
    that html validators can erroneously flag javascript errors.

    I have read the information on this page

    http://www.htmlhelp.com/tools/validator/problems.html#script

    which offers a solution. But I do not want to accidently disable the
    javascript functions of my affiliate links by adding stuff I don't
    understand.

    The W3C (and dreamweaver's) validators flag the following error -

    < found between tags. Consider using the equivalent entity (&amp =
    '&', &lt = '<', &gt = '>', &quot = quotation mark). [HTML 4.0]

    And this is the script it flags up -

    <script type="text/javascript">
    var uri = 'http://impgb.tradedoubler.com/imp/js/16125532/1079419?' +
    new String (Math.random()).substring (2, 11);
    document.write('<sc'+'ript language="javaScript" src="'+uri+'"
    charset="ISO-8859-1"></sc'+'ript>');
    </script>


    I can fix this by adding a back slash here <\/sc'+'ript>' as mentioned
    on
    http://www.htmlhelp.com/tools/validator/problems.html#script

    <quoting relevant passage>

    "A common error (and the most common source of erroneous bug reports
    for the WDG HTML Validator) occurs when writing HTML tags within a
    SCRIPT element:

    <script type="text/javascript">
    <!--
    // This is an error!
    document.write("</P>");
    // -->
    </script>

    (The fix is to add a backslash -)

    <script type="text/javascript">
    <!--
    document.write("<\/P>");
    // -->
    </script>
    </quote>


    I'm hoping someone can tell me if this is a legitimate fix and that it
    won't interfere with the javascript functions please












    --

    Free washing machine help and advice.

    www.washerhelp.co.uk

    www.xyzed.co.uk/newsgroups/top-posting.html
    xyZed, Mar 25, 2006
    #1
    1. Advertising

  2. xyZed wrote:

    > Although related to false javascript errors during validation checks,
    > this is a question about html validation.


    It's about validation of HTML documents, but it's not about "false
    javascript errors", just about common failures to understand what
    validation is.

    > I have several affiliate links stopping my pages validating. They use
    > javascript which I don't understand.


    Too bad. Your choice: get rid of them or learn to understand what this
    is about, then perhaps fix them.

    > Apparently it's a known issue
    > that html validators can erroneously flag javascript errors.


    It's not true at all.

    > I have read the information on this page
    > http://www.htmlhelp.com/tools/validator/problems.html#script
    >
    > which offers a solution.


    Indeed. Another solution is to put JavaScript code into an external
    file. Yet another, often feasible and perhaps the best, is to remove the
    JavaScript code or to replace it by something more robust (like
    replacing a fake "JavaScript link" by a real link).

    > The W3C (and dreamweaver's) validators flag the following error -
    >
    > < found between tags. Consider using the equivalent entity (&amp =
    > '&', &lt = '<', &gt = '>', &quot = quotation mark). [HTML 4.0]


    What are you referring to? Please specify the source of your quotations.

    > And this is the script it flags up -
    >
    > <script type="text/javascript">
    > var uri = 'http://impgb.tradedoubler.com/imp/js/16125532/1079419?' +
    > new String (Math.random()).substring (2, 11);
    > document.write('<sc'+'ript language="javaScript" src="'+uri+'"
    > charset="ISO-8859-1"></sc'+'ript>');
    > </script>


    The _error_ here, assuming HTML 4 rules, is the presence of "</sc",
    which starts an end tag. There is no such tag in HTML 4 and, besides, no
    end tags are allowed within a <script> element. This has _nothing_ to do
    with flagging JavaScript errors or processing JavaScript in any way.

    > I can fix this by adding a back slash here <\/sc'+'ript>' as mentioned
    > on
    > http://www.htmlhelp.com/tools/validator/problems.html#script


    Yes, or by using an external file. Or by other means, but these two are
    the simplest, probably.

    > I'm hoping someone can tell me if this is a legitimate fix and that it
    > won't interfere with the javascript functions please


    Huh? Do you expect the general level of expertise in this group to
    exceed that of the people beging the www.htmlhelp.com site? Rest assured
    it doesn't. But you can also check the _official_ (though sloppily
    written) HTML 4 specification and see that the same method is suggested
    there, though this has been hidden into an appendix:
    http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.3.2
    Jukka K. Korpela, Mar 25, 2006
    #2
    1. Advertising

  3. xyZed

    Toby Inkster Guest

    xyZed wrote:

    > I have several affiliate links stopping my pages validating. They use
    > javascript which I don't understand. Apparently it's a known issue
    > that html validators can erroneously flag javascript errors.


    Firstly, the validator is not erroneous -- it is acting correctly -- your
    HTML is invalid.

    Secondly, there is no Javascript error. The Javascript is fine in itself;
    it has simply been embedded into the HTML wrongly.

    > I have read the information on this page
    > http://www.htmlhelp.com/tools/validator/problems.html#script
    > which offers a solution. But I do not want to accidently disable the
    > javascript functions of my affiliate links by adding stuff I don't
    > understand.


    The solution proposed on that page is fine. It won't change how your
    Javascript operates.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Mar 25, 2006
    #3
  4. xyZed

    xyZed Guest

    There is circumstantial evidence that on Sat, 25 Mar 2006 16:06:58
    +0200, "Jukka K. Korpela" <> wrote
    _______________________________________________________


    >› > I have several affiliate links stopping my pages validating. They use
    >› > javascript which I don't understand.
    >›
    >› Too bad. Your choice: get rid of them or learn to understand what this
    >› is about, then perhaps fix them.


    Exactly why I posted. This is my first step.

    >› > Apparently it's a known issue
    >› > that html validators can erroneously flag javascript errors.
    >›
    >› It's not true at all.


    They flag phantom html errors, not (as I said) javascript errors,
    and of course it's not the fault of the html validators.


    >› ... Another solution is to put JavaScript code into an external
    >› file.


    That may be a good idea, would it have advantages other than the one
    discussed here I wonder? I'd have to look into how it would work for
    affiliate links and banners that are different on each page though.

    >› ..Yet another, often feasible and perhaps the best, is to remove the
    >› JavaScript code or to replace it by something more robust (like
    >› replacing a fake "JavaScript link" by a real link).


    I have yet to learn about doing such things. I hate having to use
    other people's rubbish code. It seems to me that the overwhelming
    majority of affiliate link code is poorly coded javascript. You are
    right that I should learn what code is being put on my site but I am
    so busy running and updating my site I have not had time. I do need
    the affiliate links though so it's something I've seen as a necessary
    evil.

    Thanks for the links


    --

    Free washing machine help and advice.

    www.washerhelp.co.uk

    www.xyzed.co.uk/newsgroups/top-posting.html
    xyZed, Mar 27, 2006
    #4
  5. xyZed

    xyZed Guest

    There is circumstantial evidence that on Sat, 25 Mar 2006 14:54:02
    +0000, Toby Inkster <> wrote
    _______________________________________________________


    >› Firstly, the validator is not erroneous -- it is acting correctly -- your
    >› HTML is invalid.


    >› Secondly, there is no Javascript error. The Javascript is fine in itself;
    >› it has simply been embedded into the HTML wrongly.


    The validator is flagging erroneous errors, but only because the
    poorly written javascript code fools the html validator into thinking
    the code is html (or something like that) I think I mistakenly said
    they were flagging javascript errors but the correct observation
    should be they are flagging html errors in javascript code?


    >› > I have read the information on this page
    >› > http://www.htmlhelp.com/tools/validator/problems.html#script
    >› > which offers a solution. But I do not want to accidently disable the
    >› > javascript functions of my affiliate links by adding stuff I don't
    >› > understand.
    >›
    >› The solution proposed on that page is fine. It won't change how your
    >› Javascript operates.


    Thank you.

    --

    Free washing machine help and advice.

    www.washerhelp.co.uk

    www.xyzed.co.uk/newsgroups/top-posting.html
    xyZed, Mar 27, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Blay
    Replies:
    6
    Views:
    477
    Toby A Inkster
    Dec 9, 2003
  2. Frank
    Replies:
    9
    Views:
    1,559
    David Dorward
    May 3, 2004
  3. =?Utf-8?B?Qm9i?=

    W3C Validator error: Tag Name not present

    =?Utf-8?B?Qm9i?=, Jun 14, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    472
    Ken Cox [Microsoft MVP]
    Jun 15, 2006
  4. Steve Holden
    Replies:
    0
    Views:
    772
    Steve Holden
    Feb 8, 2009
  5. David Cox

    W3c Validator usage & can't see error

    David Cox, Aug 13, 2007, in forum: Javascript
    Replies:
    2
    Views:
    105
    David Cox
    Aug 13, 2007
Loading...

Share This Page