Hello, world!

Javascript HTML

HTML Tutorial shows how JavaScript is applied in websites to execute functions in which HTML cannot perform. It will taught you about the external Javascript, internal Script, event handlers and hide scripts from older browsers.



HTML Javascript

JavaScript is a programming language frequently applied in websites adding dynamic functionality and interactivity to your website.

Internal Script

Coding your JavaScript code allows you to perform it directly inside your HTML document.
Generally script code are kept in header of the document through the use of the <script> tag, or else source codes can specify elsewhere in the documents but within the script tags.

HTML code example internal javascript:

<!DOCTYPE html>
<html>
<head>
<title>How to use Javascript Internal Script</title>
<base href="http://html-tutorial.eu/" />
<script type="text/javascript">
function Welcome(){
   alert("Welcome");
}
</script>
</head>
<body>
<input type="button" onclick="Welcome();" name="ok" value="Click"  />
</body>
</html>

HTML output internal javascript:

How to use Javascript Internal Script

External Javascript

When you need to indicate a functionality which will be applied in different HTML page, the most basic and preferred way, is to keep the scripts in a separate file and link them containing the file in your HTML documents
You can apply this using the src attribute of the script tag.
JavaScript file will contain .js extension.
First define a small function using Javascript in script.js:
function Welcome()
{
alert("Welcome");
}
Then use the external Javascript file in your HTML document:

HTML code example external javascript:

<!DOCTYPE html>
<html>
<head>
<title>Hoow to use Javascript External Script</title>
<script src="/html/script.js" type="text/javascript"/></script>
</head>
<body>
<input type="button" onclick="Welcome();" name="ok" value="Click"  />
</body>
</html>

HTML output external javascript:

Hoow to use Javascript External Script

Hide Scripts from Older Browsers

Some older browsers do not recognize JavaScriptscript.
When a browser does not support JavaScript, the script will be presented in the middle of the page instead of running it. To avoid this, you can put HTML comments surrounding the script.

Example of JavaScript:
<script type="text/javascript">
<!--
document.write("Welcome Javascript!");
//-->
</script>

Example of VBScript:
<script type="text/vbscript">
<!--
document.write("Welcome VBScript!")
'-->
</script>

Event Handlers

Event Handlers are defined javascript functions which can be invoked when any mouse or keyboard event is triggered.
There are various line codes that can help you inside your event handler.

HTML code example event handlers:

<!DOCTYPE html>
<html>
<head>
<title>How to create Event Handlers</title>
<base href="http://html-tutorial.eu/" />
<script type="text/javascript">
function EventHandler(){
   alert("HTML Event Handler");
}
</script>
</head>
<body>
<p onmouseover="EventHandler();">Point here to see an alert</p>
</body>
</html>

HTML output event handlers:

How to create Event Handlers

Point here to see an alert



The <noscript> Element

The <noscript> tag is applied to give an alternate content for users whose browser does not support client-side scripting or disabled script option.
Applying the <noscript> element can hold each element that you can seek within the <body> element of a usual HTML page.

Example of JavaScript:
<script type="text/javascript">
<!--
document.write("Welcome Javascript!");
//-->
</script>
<noscript> Javascript is not supported by your browser!</noscript>

Example of VBScript:
<script type="text/vbscript">
<!--
document.write("Welcome VBScript!")
'-->
</script>
<noscript> VBScript is not supported by your browser!</!</noscript>

Default Scripting Language

If your HTML page contains a lot of script files and scrip tags, you can specify the default scripting language for all scripts in a document by including the META tag in the HEAD.
This is a great way to avoid indicating the language each time you apply a script tag inside HTML page.

HTML code example default scripting language:

<meta http-equiv="Content-Script-Type" content="text/JavaScript" />

HTML output default scripting language: