Using External Javascript Files

by Hiroshi on June 15, 2008

in Form

Following method will guide you about how to use an external JavaScript file. Suppose this is the JavaScript code which you have applied in the head section of your web page but you want to call it via an external JavaScript file.

<script language = "Javascript">
// Declaring required variable
var digits = "0123456789";

Now remove tags from the code i.e.

// Declaring required variable
var digits = "0123456789";

Create a file and give a name like code.js and past above lines which are without tags. Save the file.

Now if this file is in the same root as your webpage then call it in webpage head section like this.

Calling An External JS File

Use code like this in head section of your webpage instead of writing all the javascript code inside your webpage’s head section.

<script language="javascript" type="text/javascript" src="code.js"></script>

Related Posts

Previous post:

Next post: