document.write inline javascript error

Discussion in 'Javascript' started by Mary Kline, May 31, 2009.

  1. Mary Kline

    Mary Kline Guest

    hi,

    I get string error when i use

    Document.Write("<script type='text/javascript' src='http://
    dl.tvunetworks.com/webplayer/myTVU.js?
    c=76600&w=550&h=385&autoplay=1&style=0'></script>");

    What is wrong in this code? Any help is appreciated.

    TIA
    -Mary
    Mary Kline, May 31, 2009
    #1
    1. Advertising

  2. Mary Kline

    Evertjan. Guest

    Mary Kline wrote on 31 mei 2009 in comp.lang.javascript:

    > hi,
    >
    > I get string error when i use
    >
    > Document.Write("<script type='text/javascript' src='http://
    > dl.tvunetworks.com/webplayer/myTVU.js?
    > c=76600&w=550&h=385&autoplay=1&style=0'></script>");
    >
    > What is wrong in this code? Any help is appreciated.


    try:

    ....</"+"script>");

    as the parser will see </script> as the end of the outer script.



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., May 31, 2009
    #2
    1. Advertising

  3. Mary Kline

    David Mark Guest

    On May 31, 2:13 pm, "Evertjan." <> wrote:
    > Mary Kline wrote on 31 mei 2009 in comp.lang.javascript:
    >
    > > hi,

    >
    > > I get string error when i use

    >
    > > Document.Write("<script type='text/javascript' src='http://
    > > dl.tvunetworks.com/webplayer/myTVU.js?
    > > c=76600&w=550&h=385&autoplay=1&style=0'></script>");

    >
    > > What is wrong in this code? Any help is appreciated.

    >
    > try:
    >
    > ...</"+"script>");
    >
    > as the parser will see </script> as the end of the outer script.


    That's just a validation error and you don't need to concatenate to
    avoid it. The exception is that there is no global "Document" object.

    document.write('<script type="text/javascript" src="..."><\/script>');
    David Mark, May 31, 2009
    #3
  4. Mary Kline

    Eric Bednarz Guest

    David Mark <> writes:

    > On May 31, 2:13 pm, "Evertjan." <> wrote:
    >> Mary Kline wrote on 31 mei 2009 in comp.lang.javascript:


    >> > Document.Write("<script type='text/javascript' src='http://
    >> > dl.tvunetworks.com/webplayer/myTVU.js?
    >> > c=76600&w=550&h=385&autoplay=1&style=0'></script>");


    >> ...</"+"script>");
    >>
    >> as the parser will see </script> as the end of the outer script.

    >
    > That's just a validation error


    No it isn’t. What’s more, the (SGML) validation error would occur at the
    second script element end-tag (or the second script element start-tag in
    the case of XHTML, take your pick).

    > and you don't need to concatenate to
    > avoid it.


    No argument there.

    > The exception is that there is no global "Document" object.


    Or “Write†method. :)
    Eric Bednarz, May 31, 2009
    #4
  5. Mary Kline

    Eric Bednarz Guest

    Eric Bednarz <> writes:

    Just for the complete picture:

    >>> > c=76600&w=550&h=385&autoplay=1&style=0'></script>");


    > […] the (SGML) validation error would occur at the
    > second script element end-tag


    Or at the string ‘")’, assuming HTML 4 strict and that the script
    element is a child of the body element.
    Eric Bednarz, May 31, 2009
    #5
  6. Mary Kline

    David Mark Guest

    On May 31, 2:45 pm, Eric Bednarz <> wrote:
    > David Mark <> writes:
    > > On May 31, 2:13 pm, "Evertjan." <> wrote:
    > >> Mary Kline wrote on 31 mei 2009 in comp.lang.javascript:
    > >> > Document.Write("<script type='text/javascript' src='http://
    > >> > dl.tvunetworks.com/webplayer/myTVU.js?
    > >> > c=76600&w=550&h=385&autoplay=1&style=0'></script>");
    > >> ...</"+"script>");

    >
    > >> as the parser will see </script> as the end of the outer script.

    >
    > > That's just a validation error

    >
    > No it isn’t. What’s more, the (SGML) validation error would occur at the
    > second script element end-tag (or the second script element start-tag in
    > the case of XHTML, take your pick).


    If that's not what was meant, then I don't know what the "outer
    script" comment was about. Regardless, there is a validation error
    without the backslash.

    >
    > > and you don't need to concatenate to
    > > avoid it.

    >
    > No argument there.
    >
    > > The exception is that there is no global "Document" object.

    >
    > Or “Write” method. :)


    Well, it doesn't get that far. :)
    David Mark, May 31, 2009
    #6
  7. Mary Kline

    Eric Bednarz Guest

    David Mark <> writes:

    >> > The exception is that there is no global "Document" object.

    >>
    >> Or “Write†method. :)

    >
    > Well, it doesn't get that far. :)


    There’s a good chance that the capitalization in the OP is the result of
    dumb automatic spelling correction. Without that, there’s indeed an
    unterminated string literal on the scripting side of things.
    Eric Bednarz, May 31, 2009
    #7
  8. Mary Kline wrote:
    > I get string error when i use


    I have yet to see an ECMAScript implementation throwing a StringError
    exception. Probably you mean something else.

    > Document.Write("<script type='text/javascript' src='http://
    > dl.tvunetworks.com/webplayer/myTVU.js?
    > c=76600&w=550&h=385&autoplay=1&style=0'></script>");
    >
    > What is wrong in this code?


    `Document' is the identifier of a W3C DOM interface, sometimes (e.g. in the
    Gecko DOM) provided as a reference to a host object that serves as holder of
    the prototype object of objects implementing this interface. The former
    object does not have a `Write' method. You want to access `document.write'
    instead, the method of the object implementing said interface, among others.

    In addition, if this code (when corrected as described above) occurs within
    a HTML `script' element, you need to escape the End Tag Open (ETAGO)
    delimiter, that is, `</' so that the markup parser does not find it.
    Otherwise that delimiter is considered the end of the `script' element and
    your script engine finds only

    ...."<script type='text/javascript'
    src='http://dl.tvunetworks.com/webplayer/myTVU.js?c=76600&w=550&h=385&autoplay=1&style=0'>

    which is an unterminated string literal. The most simple, least error-prone
    and therefore recommended way to escape `</' is to use an unregistered
    ECMAScript string escape sequence for the `/': `<\/'. Because the escape
    sequence `\/' is unregistered, it will be parsed as `/' by the script engine
    only.

    Another possibility is that you are using VBScript, in which case your
    question would be off-topic.

    That said, you shouldn't be using document.write() or its corresponding
    methods to include `script' elements unconditionally. Just include the
    `script' element:

    <script type='text/javascript'
    src='http://dl.tvunetworks.com/webplayer/myTVU.js?c=76600&w=550&h=385&autoplay=1&style=0'></script>


    HTH

    PointedEars
    Thomas 'PointedEars' Lahn, May 31, 2009
    #8
  9. Mary Kline

    David Mark Guest

    On May 31, 3:17 pm, Eric Bednarz <> wrote:
    > David Mark <> writes:
    > >> > The exception is that there is no global "Document" object.

    >
    > >> Or “Write” method. :)

    >
    > > Well, it doesn't get that far.  :)

    >
    > There’s a good chance that the capitalization in the OP is the result of
    > dumb automatic spelling correction. Without that, there’s indeed an
    > unterminated string literal on the scripting side of things.


    You mean in the script that loads?
    David Mark, May 31, 2009
    #9
  10. Mary Kline

    David Mark Guest

    On May 31, 3:25 pm, David Mark <> wrote:
    > On May 31, 3:17 pm, Eric Bednarz <> wrote:
    >
    > > David Mark <> writes:
    > > >> > The exception is that there is no global "Document" object.

    >
    > > >> Or “Write” method. :)

    >
    > > > Well, it doesn't get that far.  :)

    >
    > > There’s a good chance that the capitalization in the OP is the resultof
    > > dumb automatic spelling correction. Without that, there’s indeed an
    > > unterminated string literal on the scripting side of things.

    >
    > You mean in the script that loads?


    Never mind. I see what was meant. And no wonder I see so much
    unnecessary concatenation with document.write. Haven't worried about
    that problem since before the turn of the century. :)
    David Mark, May 31, 2009
    #10
    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. Abhi
    Replies:
    2
    Views:
    723
    E. Robert Tisdale
    Jul 3, 2003
  2. Alvin
    Replies:
    7
    Views:
    463
    E. Robert Tisdale
    May 6, 2005
  3. Ignac Vucko
    Replies:
    7
    Views:
    229
    Michael Winter
    Mar 11, 2005
  4. jullag
    Replies:
    20
    Views:
    285
    Frances
    Sep 22, 2005
  5. Frank Peterson
    Replies:
    9
    Views:
    216
    David Mark
    Jun 28, 2009
Loading...

Share This Page