Javascript: / Home / ExternalScript

External Script

Javascript functions can be coded in an external file. The major advantage of this arrangement is that the functions can be reused in other web pages.

To use an external Javascript file, the script element is added to the "head" element, but there is no included code. Instead the "src" attribute is set to the name of the external Javascript file.

    <head>
      <script src="IntroToJS.js"></script>
    </head>

A Javascript file has the ".js" extension.

Click the right mouse button on the web page. This displays a "context" menu. Select "View page source" from the menu. This will display the page source code.

On the source code page, click on the IntroToJS.js hyper text. This will display the IntroToJS.js source file.



<- InternalScript            AddEvent ->
7ExternalScript