please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 10
Client-Side Program Structure
Next
 

10.2 Including JavaScript Files

In Navigator 3.0 and Internet Explorer 3.0, the <SCRIPT> tag supports a new SRC attribute. The value of this attribute specifies the URL of a file of JavaScript code. It is used like this:

<SCRIPT SRC="../../javascript/util.js"></SCRIPT>

A JavaScript file is just that--pure JavaScript, without <SCRIPT> tags or any other HTML. A JavaScript file typically has a .js extension, and should be exported by a web server with MIME-type "application/x-javascript". This last point is important, and may require special configuration of your web server in order to successfully use JavaScript files in this way.

The behavior of the <SCRIPT> tag with the SRC attribute specified is exactly as if the contents of the specified JavaScript file appeared directly between the <SCRIPT> and </SCRIPT> tags. Any code that does appear between the open and close <SCRIPT> tags will be ignored by browsers that support the SRC attribute (although it would still be executed by browsers, like Navigator 2.0, that do not recognize the tag). Note that the closing </SCRIPT> tag is required even when the SRC attribute is specified and there is no JavaScript between the <SCRIPT> and </SCRIPT> tags.

Since both Navigator 3.0 and Internet Explorer 3.0 both support the SRC attribute, you cannot assume that any browser that understands the SRC tag also understands JavaScript 1.1. Thus it is a good idea to use the LANGUAGE attribute with the SRC attribute:

<SCRIPT LANGUAGE="JavaScript1.1" SRC="../../javascript/util.js"></SCRIPT>
Note that the web server that exports the included file also specifies the scripting language that the file contains (although perhaps not the version of the language) by specifying a MIME type for the file.

There are a number of advantages to using the SRC tag:


Previous Home Next
The <SCRIPT> Tag Book Index JavaScript and Events

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/ch10_02.htm, 7KB, , updated: 2019/10/14 16:00, local time: 2024/4/27 12:16,
TOP NEW HELP FIND: 
52.14.150.55:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://www.massmind.org/techref/language/java/script/definitive/ch10_02.htm"> [Chapter 10] 10.2 Including JavaScript Files</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to www.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .