Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

External JavaScript


We can create external JavaScript file and embed it in many html page.

It provides code re usability because single JavaScript file can be used in several html pages.

An external JavaScript file must be saved by .js extension. It is recommended to embed all JavaScript files into a single file. It increases the speed of the webpage.


Let’s create an external JavaScript file that prints Hello Kreationnext in a alert dialog box.

message.js

  1. function msg(){
  2.  alert(“Hello Kreationnext”);
  3. }

Let’s include the JavaScript file into html page. It calls the JavaScript function on button click.

index.html

  1. <html>
  2. <head>
  3. <script type=“text/javascript” src=“message.js”></script>
  4. </head>
  5. <body>
  6. <p>Welcome to JavaScript</p>
  7. <form>
  8. <input type=“button” value=“click” onclick=“msg()”/>
  9. </form>
  10. </body>
  11. </html>

Comments

comments