How to Link JavaScripts
- 1). Launch "Notepad." Open one of your HTML documents.
- 2). Locate your document's "head" section, and paste the following code there:
<script src="External_JavaScrpt_Test.js" language="javascript"
type="text/javascript"></script>
This statement links an external JavaScript file named "External_JavaScrpt_Test.js." When your Web page loads, the browser will retrieve that JavaScript file and execute the code in it. - 3). Press "Ctrl" and "S" to save your HTML file.
- 4). Press "Ctrl" and "N" to create a new document.
- 5). Add the following JavaScript code to the document:
alert("Hello")
This JavaScript code creates a pop-up message box whenever the code runs. - 6). Press "Ctrl" and "S." Since this is a new document, the "Save As" window opens.
- 7). Type "External_JavaScript_Test.js" in the "File Name" text box, and then click "Save." This file becomes the external JavaScript file that your HTML document references.
- 8). Launch Windows Explorer. Locate your HTML document and double-click it. Your browser opens and displays the Web page. When the Web page loads, the pop-up message box also appears. This occurs because your page links the external JavaScript file that contains the pop-up message code.
Source...