Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 70 - 2625 PortGPt V2.1
P. 70

    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 INTERNAL JAVASCRIPT

                      Similar to HTML5 web page, we can use any text editor like Notepad, Visual Studio Code, Sublime
                      Text, etc. to create JavaScript programs. After typing the JavaScript code, any web browser like
                      Google Chrome, Firefox, Microsoft Edge, etc. are used to view the web page. Let us create a web
                      page using internal JavaScript.

                      Follow the given steps to create JavaScript program:
                      Step 1:        Type <script type = “text/javascript”> between the <HEAD> and </HEAD> tags to use
                                  JavaScript.

                      Step 2:        Use the alert( ) method to display virtual alert box that contains some specified message
                                  and an OK button.

                      <HTML>

                      <HEAD>
                      <TITLE> My First JavaScript </TITLE>

                      <SCRIPT TYPE="text/javascript">

                      alert("Hello World!");

                      </SCRIPT>

                      </HEAD>

                      <BODY>

                      This message box is displayed using JavaScript.

                      </BODY>

                      </HTML>

                      68    Premium Edition-VIII

| 65 66 67 68 69 70 71 72 73 74 75 |