basics of script tag and attributes, where to put

A

awebguynow

I've always thought a script tag to ref and ext JS file, should be
structured, like so
<script type="text/javascript" src="foo.js"></script>

I've noticed in some of the Venkman tutorials only use the "src"
attribute.
What is the best coding style ?

Also, I've done some event-driven JS programming (onEvent), but I've
also seen examples of <script> placed anywhere in an html file. I
think the whole html file is sent to the browswer, and JS called where
ever it is placed, but I am having calling a function in an external
file.

I plan on using Venkman more to debug, since I have no desire to get
MS's VS or MS Script Editor which comes with Office XP.
 
P

Patient Guy

awebguynow said:
I've always thought a script tag to ref and ext JS file, should be
structured, like so
<script type="text/javascript" src="foo.js"></script>

This is technically an HTML question and not Java/ECMAscript. I would
advise you to follow what you consider the most authoritative standard or
specification you have. (Note that the W3 Consortium does not refer to
their "standards" or "specifications" as such, but more modestly refers to
them as "recommendations.")

When deciding who is authoritative in the event of a dispute, you might
consider who first originated the concepts involved in principle. But in
practice, reality shows that you will also make decisions based on the
usage of consensus.
I've noticed in some of the Venkman tutorials only use the "src"
attribute.
What is the best coding style ?

The developers of Venkman would probably not be considered even remotely
authoritative when it comes to writing HTML properly, and they would
probably not claim to be authoritative as well.

You could consider them authoritative when it comes to writing Javascript
debuggers however.
Also, I've done some event-driven JS programming (onEvent), but I've
also seen examples of <script> placed anywhere in an html file. I
think the whole html file is sent to the browswer, and JS called where
ever it is placed, but I am having calling a function in an external
file.

Script elements can be placed legally within the head and body of the HTML
document. The only thing that you have to keep in mind is that everything
is defined and objectified---the document content, the scripts---in the
order in which it is read, and reading is synchronous generally.

Thus if you make reference to (call, make use of) a variable or function
before the actual definition of that variable or function, expect an error
or exception. Note that variables or functions coded within the scope of
a function is not referencing or calling or making use of those variables
or functions when the function containing them is being defined.

When external JS file are "included" within an HTML document, it is
equivalent to inserting all their code at that place in the document where
the script elements are placed. Make sure they are relatively error-free
before moving their code to an external JS file: a single coding (not
runtime) error in some (maybe all) browsers effectively cancels all
variables and functions defined in that file as being part of the global
scope.

I plan on using Venkman more to debug, since I have no desire to get
MS's VS or MS Script Editor which comes with Office XP.

You should reconsider this if you intend that your scripts get widespread
use. The (horrible?) fact of life is that Internet Explorer is still the
giant in browser usage, and it differs from Mozilla/Firefox/real
Javascript browsers in only a small number of ways.

I do the heavy-lifting (initial code development) in Firefox with Venkman
and the Error2 console, as well as those extensions that display element
information right in the rendered page.

And then I set about to see how it runs in MSIE with the Script Debugger
handy and a battery of information about how to use ActiveX objects, if
needed.
 
R

Randy Webb

awebguynow said the following on 9/6/2006 1:35 PM:
I've always thought a script tag to ref and ext JS file, should be
structured, like so
<script type="text/javascript" src="foo.js"></script>

According to W3C and the HTML Specs, that is what is expected from the
Validator.
I've noticed in some of the Venkman tutorials only use the "src"
attribute.
What is the best coding style ?

Personal preference. I have yet to see (with one exception) where
<script src="someFile.js"></script> didn't work properly. That one
exception is in IE and that is only if you have a VBScript script
element in the page first.

As for the type attribute itself, it is ironic that the W3C validator
insists upon a type attribute yet there are no official MIME Types for
script elements.
I plan on using Venkman more to debug, since I have no desire to get
MS's VS or MS Script Editor which comes with Office XP.

You can totally debug scripts without any debugger other than the
browsers themselves. And, Firefox doesn't always give a true error
message. See the thread from just today entitled "inserting scripts into
the DOM" with respect to the error messages given by IE, Opera and Firefox.
 
M

Michael Winter

Randy Webb wrote:

[snip]
As for the type attribute itself, it is ironic that the W3C validator
insists upon a type attribute yet there are no official MIME Types
for script elements.

Yes there are, though there wasn't at the time the Recommendation was
written.

[snip]

Mike
 
M

Michael Winter

Patient said:
[snip]
I plan on using Venkman more to debug, since I have no desire to
get MS's VS or MS Script Editor which comes with Office XP.

You should reconsider this if you intend that your scripts get
widespread use.

Why? The OP wrote "more to debug", not "do all of my testing". It seems
that he intends to do almost precisely what you described for yourself:
primary development with a decent debugging tool, then testing
afterwards in IE (having hopefully eliminated all bugs, anyway).

[snip]

Mike
 
P

Patient Guy

Michael Winter said:
Patient said:
[snip]
I plan on using Venkman more to debug, since I have no desire to
get MS's VS or MS Script Editor which comes with Office XP.

You should reconsider this if you intend that your scripts get
widespread use.

Why? The OP wrote "more to debug", not "do all of my testing". It seems
that he intends to do almost precisely what you described for yourself:
primary development with a decent debugging tool, then testing
afterwards in IE (having hopefully eliminated all bugs, anyway).

My reading of his statement is that he does not plan to use a development
environment provided by MS, typically to debug script execution in IE. He
did not state whether he wanted his scripts to run in IE or whether he
cared if they did or not. If you say there is an ambiguity in his
comments, I can agree.

At any rate, he might quickly learn the necessity of having to use a MS-
provided development environment if he also wanted those scripts to run in
IE.
 
A

awebguynow

I've had trouble putting <script> tag in html near the bottom of a
page, even though I've used this placement before, as instructed, with
an external script I downloaded.

When placing the script tag in this position, I get the popup showing
IE error:
"cannot open the Internet site ..."
 
A

Andy Dingley

Randy said:
As for the type attribute itself, it is ironic that the W3C validator
insists upon a type attribute yet there are no official MIME Types for
script elements.

Does the W3C validator (a HTML validator) require a particular value /
values for the type attribute, or merely that it exists ?

It's only valid HTML if the type attribute is used, but HTML doesn't
specify what it ought to be. After all, even VBScript is valid HTML.
The choice of a correct value for type is one question, the choice of a
widely-supported and web-appropriate one is another, but neither of
these are questions about HTML validity.
 
A

awebguynow

IE error: "cannot open the Internet site ..." .
only occurs when the <script> tag is inside a div..
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top