Ultra fast cheap  linux and windows hosting
javascript tutorial Browse Advanced JavaScript Tutorial
Browse JavaScript Script resources
Browse JavaScript FAQS
JavaScript Tutorial: Browse
javascript tutorial
Home >> Tutorials >> Basic Javascript Tutorials

Javascript Introduction:
 
What is javascriptEmbedding JS into HTMLSpecifying JS version
Specifying fileHiding script 

What is Javascript?
JavaScript is an object-oriented scripting language developed by Netscape that allows you to create web pages. Javascript is a client-side scripting language. This means the user's browser will be running the script. This is opposite to client-side is server-side, which occurs in a language like PHP. These PHP scripts are run by the web hosting server.

JavaScript is not Java.

JavaScript and Java are similar in some ways but fundamentally different in others. Java is a compiled programming language, similar to languages like C, C++, or Pascal.

JavaScript is a scripting language, meant  for small programs used only from within web browsers. A JavaScript script can't run alone, without the browser, the way a Java program does. JScript is Microsoft's version of JavaScript.

Top




Embedding JavaScript into a HTML-page

JavaScript code is embedded directly into a HTML-page using <script>  and </script> tags. It is possible to  embed  many scripts into a single document , using multiple SCRIPT tags.

A typical format for a javascript embedded into a HTML file would look like :
<script ="JavaScript">

<!--

Javascript statements
.
.
//-->

</script>

JavaScript is case sensitive:
Unlike HTML, Javascript is case-sensitive.

Top




Specifying the JavaScript Version

As mentioned above, there are several versions of JavaScript supported by certain browsers and browser  versions. You can specify the javascript version using  the LANGUAGE attribute.
Eg:

<script language ="JavaScript1.1">

<!--

  Javascript statements
//-->

</script>

Statements within a <SCRIPT> tag are ignored if the browser does not support the javascript version specified in the LANGUAGE attribute. In other words, you can specify that a section of  code only be executed by browsers which support a particular version of JavaScript.

Eg:

    1)Navigator 2.0 executes code within the <SCRIPT LANGUAGE="JavaScript"> tag; it ignores
     code within the <SCRIPT LANGUAGE="JavaScript1.1"> and <SCRIPT

     LANGUAGE="JavaScript1.2"> tags.

    2) Navigator 3.0 executes code within the <SCRIPT LANGUAGE="JavaScript"> and <SCRIPT

     LANGUAGE="JavaScript1.1"> tags; it ignores code within the <SCRIPT

     LANGUAGE="JavaScript1.2"> tag.

    3) Navigator 4.0 executes code within the <SCRIPT LANGUAGE="JavaScript">, <SCRIPT

     LANGUAGE="JavaScript1.1">, and <SCRIPT LANGUAGE="JavaScript1.2">

Top




Specifying a file for Javascript Code

You can include an external file containing JavaScript code into a HTML file. SRC, another attribute of the SCRIPT  tag is used for this purpose.  This feature is helpful when you want to hide your javascript code from others (HTML Source code of all web pages can be seen from the borwser. Using this feature you can hide your javascript code from others)

For example: You can have all your javascript statements in a file called 'myjavascript.js' and can include into your HTML file as shown below:

<HEAD>
<TITLE>My Javascript Page</TITLE>

<SCRIPT SRC="myjavascript.js">

</SCRIPT>

</HEAD>

<BODY>

HTML Code

.

.

.

<BODY>

The external file is simply a text file containing only JavaScript statements and function definitions  and filename ends with  the extension ".js". The SRC attribute can specify any URL, relative or absolute. All JavaScript statements within a <SCRIPT> tag with a SRC attribute are ignored (unless there was an error in file inclusion).

Top




Hiding Scripts within Comment Tags

Only Netscape Navigator versions 2.0 and later recognize JavaScript. If a browser does not recognize javascript code, the whole code in displayed when you see the HTML document. To ensure that your JavaScript code is not displayed by old browsers, place Javascript inside comment fields. The markup to begin a comment  field is <!-- while you close a comment field using  //-->.

Eg:
<SCRIPT>

<!-- Hide script contents from old browsers that does not javascript.

Include JavaScript statements...

// Finish hiding here. -->

</SCRIPT>

Top



[CaRP] php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
About Focus on JavaScript
JavaScript

Farewell
3 Sep 2011 at 11:38pm

After seven years of writing content for this site I have decided that it is time to move on.

Farewell originally appeared on About.com Focus on JavaScript on Sunday, September 4th, 2011 at 04:38:29.

Permalink | Comment | Email this


Analog Clocks
3 Sep 2011 at 12:41am

Old JavaScript never die, they just get rewritten. In between writing new scripts and tutorials, I occasionally revisit old scripts and look into what needs to be done to update them. Some time after first writing them I revisited both my original analog clock script and also the more recently written multi-clock version to see what needed to be done to modernise them. In the case of the multi-clock version it already has most of the code enclosed within objects to minimise interference from other scripts and completely unobtrusive and so I made just a few minor tweaks to the code to make it slightly shorter without changing the way it works at all. The original script underwent somewhat bigger changes as I reworked the code based on some of what is in the multi-clock version to remove the need for the body script and to make it unobtrusive. There is no point in my also amending it to enclose the code in an object because that would just make it the same as the multi-clock version. If you write your own scripts you will need to revisit them occasionally to bring the code more up to date. The biggest problem when you have lots of scripts is to prioritise which ones to update first.

Analog Clocks

Analog Clocks originally appeared on About.com Focus on JavaScript on Saturday, September 3rd, 2011 at 05:41:51.

Permalink | Comment | Email this


Slide Show
2 Sep 2011 at 6:15am

Let your visitors step through a selection of images one after the other with a JavaScript slideshow. A variation on the mouseover script that will load a succession of images in a "slide show" as your visitor selects the "next" link. They can even go back to the previous image and the entire slideshow wraps around to the first image when they reach the end.

Slide Show

Slide Show originally appeared on About.com Focus on JavaScript on Friday, September 2nd, 2011 at 11:15:02.

Permalink | Comment | Email this


Cycling Banner
1 Sep 2011 at 7:30am

Animate your images with JavaScript. You can use JavaScript to replace images on your page at regular intervals. This is useful for when you want to use photos or other images that can't be incorporated into animated gifs.

Cycling Banner

Cycling Banner originally appeared on About.com Focus on JavaScript on Thursday, September 1st, 2011 at 12:30:33.

Permalink | Comment | Email this


Tbodies and Rows
31 Aug 2011 at 3:10am

The only difference between referencing rows in the thead or tfoot of a table and referencing them in a tbody is that a table can have more than one tbody. In this example we look at how to build two nested loops that will reference every row within each tbody in order to apply a class to every even row in each tbody.

Tbodies and Rows

Tbodies and Rows originally appeared on About.com Focus on JavaScript on Wednesday, August 31st, 2011 at 08:10:54.

Permalink | Comment | Email this


Table Footer
30 Aug 2011 at 4:08am

The footer of a table is as easy toreference in JavaScript as the table heading is. We could insert a row the same way as we did with the head except referencing tfoot instead of thead or we can simply call deleteRow to delete a specified row (which would also work for deleting heading rows).

Table Footer

Table Footer originally appeared on About.com Focus on JavaScript on Tuesday, August 30th, 2011 at 09:08:09.

Permalink | Comment | Email this


Table Heading
29 Aug 2011 at 6:07am

Adding a heading row to a table is as simple as

Table Heading

Table Heading originally appeared on About.com Focus on JavaScript on Monday, August 29th, 2011 at 11:07:20.

Permalink | Comment | Email this


Table Caption
28 Aug 2011 at 3:03pm

The DOM call to update a table caption is very straightforward as you can access it directly once you reference the table rather than having to hunt within the table for it.

Table Caption

Table Caption originally appeared on About.com Focus on JavaScript on Sunday, August 28th, 2011 at 20:03:24.

Permalink | Comment | Email this


Switch Fallthrough
27 Aug 2011 at 2:37am

In a JavaScript switch statement when a particular case is run it processes all of the code through to the next break statement. This means that the code may fall through past other case statements. This can lead to complications when you are trying to debug the code and you can't tell whether there is a break statement missing before a case statement. By not allowing cases to fall through and run the code of subsequent cases (except where the cases share all identical code) you can remove this problem without having to make significant changes to the code.

Switch Fallthrough

Switch Fallthrough originally appeared on About.com Focus on JavaScript on Saturday, August 27th, 2011 at 07:37:08.

Permalink | Comment | Email this


Optional Function Arguments
26 Aug 2011 at 6:05am

JavaScript functions can accept a variable number of arguments. JavaScript provides a completely different way of making function arguments optional from the way that most programming languages do it. JavaScript's way gives you the maximum possible flexibility.

Optional Function Arguments

Optional Function Arguments originally appeared on About.com Focus on JavaScript on Friday, August 26th, 2011 at 11:05:08.

Permalink | Comment | Email this



Page contents: itechies.net - javascript introduction
javascript tutorial