Load external JS using Javascript...

H

howachen

Hi

Some examples use the following codes in order to load external JS...

e.g.

document.write("<scr"+"ipt language=javascript ....

I have one qusestion,

Why need to separate the "script" into "<scr"+"ipt ...?

Many people are using this way but i really don't know why...


Thanks.


howa
 
T

Thomas 'PointedEars' Lahn

Some examples use the following codes in order to load external JS...

e.g.

document.write("<scr"+"ipt language=javascript ....

I have one qusestion,

Why need to separate the "script" into "<scr"+"ipt ...?

Many people are using this way but i really don't know why...

Because those people lack a minimum clue about what they are doing. Using
the `language' attribute, often instead of the required `type' attribute,
is another indication of that. It is not at all necessary to do the above.
It might have been an attempt at working around the Netscape 4.x Run-Length
Bug (NRLB), but since this is rather a heisenbug, it is not a reliable
approach.

This code is probably based on the common misconception that "</scr" + "ipt"
would prevent a markup parser from accidentally recognizing the end tag of
a dynamically generated `script' element as the end tag of the generating
`script' element, and therefore the start tag of a dynamically generated
`script' element as the start tag of a generating `script' element.

In fact, the latter is unnecessary and the former only works for tag soup
parsers that recognize `</script>' as end of `script' element content. A
standards compliant parser recognizes the ETAGO delimiter (`</') as the
end of the `script' element's CDATA content. Therefore, the reasonable
approach is to write "<\/script>" instead of "</script>" within the HTML
`script' element (that goes for other generated end tags as well). And so
far, there is no known (tag soup) parser that recognizes `<script' within
the `script' element as the start tag of a generating `script' element
before it is generated.


PointedEars
 
D

d

Hi

Some examples use the following codes in order to load external JS...

e.g.

document.write("<scr"+"ipt language=javascript ....

I have one qusestion,

Why need to separate the "script" into "<scr"+"ipt ...?

Many people are using this way but i really don't know why...

Because some browsers would, back in the day at least, throw up errors if
there was a script tag in a block of javascript. I worked at an advertising
agency that had libraries of JS to get round such limitations... Whether
that's still the case is unknown to me :)
 
E

Evertjan.

d wrote on 20 feb 2006 in comp.lang.javascript:
Because some browsers would, back in the day at least, throw up errors
if there was a script tag in a block of javascript. I worked at an
advertising agency that had libraries of JS to get round such
limitations... Whether that's still the case is unknown to me :)

You don't know if you are still working there?
 
R

Richard Cornford

d said:
Because some browsers would, back in the day at least, throw
up errors if there was a script tag in a block of javascript.
<snip>

All (at least SCRIPT element understanding) browsers have had problems
with </SCRIPT> tags, at least their HTML parsers have as they have no
choice but consider occurrences of </SCRIPT> that follow an opening
SCRIPT tag as terminating the script element (HTML parsers cannot see
that such occurrences within javascript strings are not meant for their
attention). However, I have never encountered a browser that knew what a
SCRIPT element was and had a problem with opening script tags within
javascript strings. Can you name one that does?

The breaking up of SCRIPT tags in strings follows from a
misidentification of a real issue and was introduced and propagated
because it deals with the real practical issue as a side effect and is
harmless otherwise (much like most eval abuse 'works' and is harmless
otherwise, i.e. the inefficient alternative to an objectively superior
option). It is, was, and always will be, an old wives tale that 'works'
(in the broadest sense) and keeps people from seeing the real cause of
the problem and so addressing the real issue. It is what is known as
'programming by coincidence'; always popular among the masses who script
web pages.

Richard.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top