Page 328 - Webapplication11_C11_Flipbook
P. 328

External JavaScript
              JavaScript code can be written in a file and saved with the .js extension and this file can then be linked inside the
              <HEAD> and </HEAD> tags of the HTML document in which we want to add this code. The SRC attribute of the
              <script> tag allows to give path of the JavaScript file. The syntax to add external JavaScript is:

                 <HEAD>
                 <SCRIPT TYPE="text/javascript" SRC="D:\first.js">
                 </SCRIPT>
                 </HEAD>
              Note that there are many other scripting languages, hence, it is recommended to use the TYPE attribute with the
              <SCRIPT> tag and set its value to Text/JavaScript to specify that scripting language we are using.
              Creating a Web Page with External Javascript

              To use external JavaScript, follow the given steps:
              Step 1:  Open the Notepad and type the following line:
                       alert("Hello World");
              Step 2:  Save the file with .js extension.
              Step 3:  Open another Notepad and type the following code:

                       <HTML>
                       <HEAD>
                       <TITLE> My First JavaScript </TITLE>
                       <SCRIPT TYPE="Text/javascript" SRC="external.js">
                       </SCRIPT>
                       </HEAD>
                       <BODY>
                       This message box is displayed using external JavaScript.
                       </BODY>
                       </HTML>
              Step 4:  Save the file with .html extension and open the web page in a web browser. You will get the same output as
                       the  previous web page.















                326     Touchpad Web Applications-XI
   323   324   325   326   327   328   329   330   331   332   333