HTML Script, Uses of JavaScript in HTML

0
104
html script

HTML Script

HTML script tag is used to specify client-side script such as JavaScript. It facilitates you to place a script within your HTML document. JavaScript is used for image manipulation, form validation, and dynamic content.

<html>
<head>
   <title>Javascript Script</title>
 <script type="text/javascript">
    function Hello(){ alert("Hello, Everyone"); }
 </script> 
</head> 
<body>
    <input type="button" onclick="Hello();" name="ok" value="Click Me" /> 
</body> 
</html>

External Javascript

If an identification code is used on several pages of a website, external Javascript files are beneficial. You only need to include a reference to the external code in those pages that actually require that code.A Javascript file will have extension as .js and it will be included in HTML files using <script> tag.

Consider we define a small function using Javascript in script.js which has following code:

function Hello(){ alert("Hello, Everyone"); }

Now let’s make use of the above external Javascript file in our following HTML document:

<html> 
<head>
   <title>Javascript Externa; Script</title> 
<script src="/html/script.js" type="text/javascript"/></script> 
</head> 
<body> 
    <input type="button" onclick="Hello();" name="ok" value="Click Me" /> 
</body> 
</html>

Internal Javascript

Internal Javascript code is code that’s placed anywhere within the web page between the HTML tags. Many web developers choose to place their Javascript code before the tag.

<html> 
<head>
   <title>Javascript Script</title> 
<script type="text/javascript"> 
function Hello()
 { alert("Hello, Everyone"); } 
</script> 
</head> 
<body> 
    <input type="button" onclick="Hello();" name="ok" value="Click Me" /> 
</body> 
</html>

HTML <noscript> Tag

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

<html> 
<head> 
    <title>noscript </title> 
</head> 
<body> 
   <p id="demo"></p> 
   <script> document.getElementById("demo").innerHTML = "Hello JavaScript!"; </script> 
  <noscript>Sorry, your browser does not support JavaScript!</noscript> 
</body> 
</html>

A browser without support for JavaScript will show the text written inside the noscript element.

LEAVE A REPLY

Please enter your comment!
Please enter your name here