Page 144 - Computer Genius Class 08
P. 144

The syntax to add internal JavaScript is:

                  <HEAD>
                  <SCRIPT>
                  JavaScript code

                  .....
                  </SCRIPT>
                  <HEAD>
                  OR
                  <BODY>
                  <SCRIPT>

                  JavaScript code

                  .....
                  </SCRIPT>
                  </BODY>
                  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.

                      142    Computer Genius-VIII
   139   140   141   142   143   144   145   146   147   148   149