HTML SCRIPT

Client-side scripting refers to the type of computer programs that are executed by the user’s web browser. JavaScript is the most popular client-side scripting language on the web.

Common uses for JavaScript are form validation, generate a pop-up alert box message, creating image gallery, dynamic changes of content, etc.

Adding a Script to HTML Document

The <script> element is used to define a client-side script.

The script in the example below writes Hello World! to the HTML output:

EXAMPLE
<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>EMBEDDED JAVASCRIPT EXAMPLE</title>        
</head>
<body>
    <script>
        document.write("HELLO WORLD!");
    </script>
</body>
</html>
Result

Calling an External Script

You can also place your scripts into a separate file, and then call that file through the src attribute in your HTML document. This is useful if you want the same scripts available to multiple documents — it saves you from repeating the same task over and over again, and makes your website much easier to maintain.

EXAMPLE
<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>EXTERNAL JAVASCRIPT EXAMPLE</title>        
</head>
<body>
    <script src="HELLO.JS"></script>
</body>
</html>
Result

The HTML noscript Element

The <noscript> element is used to provide an alternate content for users that have either disabled scripts in their browser or have a browser that doesn’t support client-side scripting.

The noscript element can contain all the HTML elements that you’d include inside the <body>element of a normal HTML page.

EXAMPLE
<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>NO-SCRIPT EXAMPLE</title>        
</head>
<body>
    <script>
        document.write("HELLO WORLD!");
    </script>
    <noscript>
        <p>SORRY, YOUR BROWSER DOES NOT SUPPORT JAVASCRIPT!</p>
    </noscript>
</body>
</html>
Result