document.write inline javascript error

M

Mary Kline

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
 
E

Evertjan.

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.
 
D

David Mark

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





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>');
 
E

Eric Bednarz

David Mark said:
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. :)
 
E

Eric Bednarz

Just for the complete picture:
[…] 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.
 
D

David Mark

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.
No argument there.


Or “Write” method. :)

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

Eric Bednarz

David Mark said:
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.
 
T

Thomas 'PointedEars' Lahn

Mary said:
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
 
D

David Mark

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?
 
D

David Mark

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. :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top