How to Add JavaScript to Your Website Using HTML

Open up the Notepad or other simple text-editing software., Start a basic HTML document., Add a script tag to the HTML's head, and let the text editor know that you'd like to use a javascript language to write your HTML's javascript "program"., Call...

8 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 1: Open up the Notepad or other simple text-editing software.

    Use the Run Command (Windows key+R), then type notepad and press Enter.

    It can also be found in Start menu > Accessories > Notepad.
  2. Step 2: Start a basic HTML document.

    Include the HTML tags, including the <head> and </head> combination pair as well as the <body> and </body> combination pair.

    Type all the needed tags to start the page.

    It should look like this or the below image: <html> <head> </head> <body> </body> </html>

    Add a <script language="javascript"> tag in the head.

    If you want the script to automatically run when the site loads, don't do a function.

    If you want to call it, do a function.

    For this example, we will alert the user. <html> <head> <script language="javascript"> alert("Hi there, and welcome.") </script> </head> <body> </body> </html>

    Add it a src (stands for "src") property to the script tag and include the complete web address of the file.

    Make sure to link directly to the Javascript file and not the page's URL where the script is being called from by the other page's creator. <html> <head> <script type="text/javascript" src="http: </script> </head> <body> </body> </html>

    Following the </body> tag, include the </html> tag. , Save the page as (anything).html, it will become a web page.

    Double click on the icon, and watch as your page loads and an alert box comes up.
  3. Step 3: Add a script tag to the HTML's head

  4. Step 4: and let the text editor know that you'd like to use a javascript language to write your HTML's javascript "program".

  5. Step 5: Call up other JavaScript scripts using a JavaScript function

  6. Step 6: if you know where the script file can be found.

  7. Step 7: Make sure to end your HTML document.

  8. Step 8: Save your page.

Detailed Guide

Use the Run Command (Windows key+R), then type notepad and press Enter.

It can also be found in Start menu > Accessories > Notepad.

Include the HTML tags, including the <head> and </head> combination pair as well as the <body> and </body> combination pair.

Type all the needed tags to start the page.

It should look like this or the below image: <html> <head> </head> <body> </body> </html>

Add a <script language="javascript"> tag in the head.

If you want the script to automatically run when the site loads, don't do a function.

If you want to call it, do a function.

For this example, we will alert the user. <html> <head> <script language="javascript"> alert("Hi there, and welcome.") </script> </head> <body> </body> </html>

Add it a src (stands for "src") property to the script tag and include the complete web address of the file.

Make sure to link directly to the Javascript file and not the page's URL where the script is being called from by the other page's creator. <html> <head> <script type="text/javascript" src="http: </script> </head> <body> </body> </html>

Following the </body> tag, include the </html> tag. , Save the page as (anything).html, it will become a web page.

Double click on the icon, and watch as your page loads and an alert box comes up.

About the Author

G

Gary Gordon

Professional writer focused on creating easy-to-follow creative arts tutorials.

38 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: