Introduction:-
Here in this tutorial I will tell you how to use an External JavaScript file, so if you have a chunk of code that will be used in multiple pages, you will have to make one Script and then call it from the pages instead of making the same code over and over again!
Solution:-
Open a Text Editor and paste the following code and save it as
<<Name>>.js I named it 'External Script.js', this is just a script that will show the time but here you can insert whatever you want!!
Code:
test = new Date()
month = test.getMonth()
month = (month * 1) + 1
day = test.getDate()
year = test.getFullYear()
document.write(" ",month,"/",day,"/",year," ")
And this code in the main HTML file:-
Code:
<SCRIPT SRC="External Script.js">
</SCRIPT>
Explanation:-
Code:
<SCRIPT SRC="External Script.js">
</SCRIPT>
Here we are just calling the External Script, instead of "External Script.js" make whatever name you named your script!
A Preview:-
None
Conclusion:-
As Always Feedback is welcome and the full source is attached!!