PHP tutorials, html tutorial, photoshop tutorial, ajax tutorials,java tutorial, web design tips tutorials, css tutorial, visual basic tutorial, dreamweaver tutorial, php tutorial, html tutorials, c++ tutorial, javascript tutorial, windows tutorials, free flash tutorials, free photoshop source codes, sql tutorial
Web Development Tutorials, Programming Tutorials, PHP Script Index
Home | Forums | Downloads | Books | Submit Content | Links

Programming Articles

  PHP articles
  MySql articles
  Visual Basic.Net articles
  Java articles
  ASP articles
  ASP.Net articles
  Visual Basic articles
  CSS articles

Programming Tutorials

  PHP tutorials
  MySql tutorials
  Visual Basic.Net tutorials
  Java tutorials
  ASP tutorials
  ASP.Net tutorials
  Visual Basic tutorials
  HTML tutorials
  CSS tutorials

Programming Source Codes

  PHP scripts
  Visual Basic.Net scripts
  JavaScript scripts
  ASP scripts
  ASP.Net scripts
  Visual Basic scripts

Our Partners

  Free Resources
  Publisherbank
  Free Link Directory
  PHP Magazine
  Webmaster Passion
  Search Engine Bank
  Free Directory Site
  Free PHP Scripts
  Links Shopping Mart
  Variety Bazar
  Urdu Office Tutorials
  Evernew Scripts
  Evernew Scripts
  Evernew Directory
  Our Achievements
  Web templates
  Buy and Sell Templates
  Text Link Traders
  Directory Metro
  Gifts Choice
  Valentines Ecards
  Template Directory

Using External JavaScript Files

Date:2007-03-02

by Amrit Hallan

When you have lots of JavaScript functions and you plan to use them on many web pages, it is always advisable to keep them in a separate file, and then include that file on every page where those functions are required. This way, you can better organize them, you don't have to copy/paste the code again and again (imagine if it runs to 100 or more lines!!), and you'll be forced to write more generalized code for better integration and scalability.

Besides, enclosing the common JavaScript routines in external files keeps your web pages uncluttered and search engine spiders and crawlers are able to reach the important content easily. They don't have to shuffle through tens of lines of scripts.

In the first edition [that appeared in my newsletter - BYTESWORTH REACHOUT] of my article I had omitted the process of creating the external JavaScript files, but when one of my readers asked me how to do it, I had to re-write the article.

It's very simple. Use any text editor of your liking (if you hand-code your HTML, you can use the same editor that you use for your HTML editing). Write the required code, and save the file with .js (dot js) extension.

I'm going to give you a small example.

Suppose your JavaScript file is "myjfuncs.js".

and it has a function to return the bigger number of the two supplied as parameters (you can simply start with the function, no need to write <script> or some other stuff):

function bigger(num1, num2) { var holdbig; if (num1<num2) { holdbig=num2; } else if(num1>num2) { holdbig=num1; } else { holdbig=num1; } return holdbig; }

In a similar manner, we can have

function smaller(num1, num2) {

}

When we want to use this precious file full of JavaScript functions, we use this line:

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

So when we use one of its functions in a JavaScript:

<script language="javascript">

var n1=90; var n2=7; alert ("The bigger number is: " + bigger(n1, n2));

</script>

In this way, we can use all the complex functions contained in the myjfuncs.js file.

About the Author

Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at amrit@bytesworth.com or http://www.bytesworth.com. For more such articles, visit http://www.bytesworth.com/articles You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com



Desclaimer | Privacy Policy | Submit Content | Links | Link to Us | Sitemap |Contact Us
Copyright Programming Tutorials, Web Development Tutorials, Source codes © All Rights are Reserved.
Powered By Evernew Solutions

Credit Card Consolidation - Car Insurance - Flights - Guitar Books