Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > basics of script tag and attributes, where to put

Reply
Thread Tools

basics of script tag and attributes, where to put

 
 
awebguynow
Guest
Posts: n/a
 
      09-06-2006
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.

 
Reply With Quote
 
 
 
 
Patient Guy
Guest
Posts: n/a
 
      09-06-2006
"awebguynow" <(E-Mail Removed)> wrote in comp.lang.javascript:

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


 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      09-06-2006
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-06-2006
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
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-06-2006
Patient Guy wrote:

> "awebguynow" <(E-Mail Removed)> wrote in comp.lang.javascript:


[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
 
Reply With Quote
 
Patient Guy
Guest
Posts: n/a
 
      09-07-2006
Michael Winter <(E-Mail Removed)> wrote in comp.lang.javascript:

> Patient Guy wrote:
>
>> "awebguynow" <(E-Mail Removed)> wrote in comp.lang.javascript:

>
> [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.
 
Reply With Quote
 
awebguynow
Guest
Posts: n/a
 
      09-19-2006
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 ..."

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      09-19-2006

Randy Webb wrote:
> 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.

 
Reply With Quote
 
awebguynow
Guest
Posts: n/a
 
      09-21-2006
IE error: "cannot open the Internet site ..." .
only occurs when the <script> tag is inside a div..

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
How Can I put XSL tag inside HTML form tag? RC Java 2 05-10-2005 06:26 PM
How Can I put XSL tag inside HTML form tag? RC XML 2 05-10-2005 05:55 PM
netscape 4.7: onmouseover not working when i put <a> tag within a div tag Eqbal Z Javascript 6 08-27-2003 12:56 AM



Advertisments