Javascript Introduction:
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
About Focus on JavaScript
Focus on JavaScript
The Best Place to Attach JavaScript
15 Mar 2010 at 12:33am
When it comes to modern unobtrusive JavaScript the only references to JavaScript in your HTML should be script tags to reference the external scripts that handle everything else that is JavaScript related. There are two possible places to put those script tags and here we look at the pros and cons of each.
The Best Place to Attach JavaScript
The Best Place to Attach JavaScript originally appeared on About.com Focus on JavaScript on Monday, March 15th, 2010 at 05:33:25.
Permalink | Comment | Email this
Properties of RegExp
14 Mar 2010 at 11:52am
Regular Expressions capture a lot of information about your text in a number of properties. When you process a Regular Expression it can not only update the text string that you are processing it against. There are many properties associated with Regular Expressions and some of these can be set to change the way the expression is processed while others return information about the processing that was performed and even pieces of the string. The twentieth Regular Expressions tutorial introduces you to these properties and what you can do with them.
Properties of RegExp
Properties of RegExp originally appeared on About.com Focus on JavaScript on Sunday, March 14th, 2010 at 16:52:41.
Permalink | Comment | Email this
Analog Clocks
13 Mar 2010 at 2:41am
Old JavaScripts 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, March 13th, 2010 at 08:41:51.
Permalink | Comment | Email this
Bubbles
12 Mar 2010 at 9:12am
JavaScript can enhance a theme web site. Is the subject of your site something to do with the sea or water? Give your visitors a sense of actually being there. This JavaScript gives your web page an underwater feel with bubbles slowly making their way up the page.
Bubbles
Bubbles originally appeared on About.com Focus on JavaScript on Friday, March 12th, 2010 at 15:12:59.
Permalink | Comment | Email this
Enhanced Suckerfish Menu
11 Mar 2010 at 2:22am
The best menus are still functional when JavaScript is disabled.
The suckerfish dropdown menu was the name given to the first dropdown menu for web pages designed using just HTML and CSS with no JavaScript required (except to handle some CSS support that is missing from Internet Explorer). In my version of this menu I have also added some further JavaScript that will enhance the functionality of the menu without stopping the menu from still being usable when JavaScript is disabled.
Enhanced Suckerfish Menu
Enhanced Suckerfish Menu originally appeared on About.com Focus on JavaScript on Thursday, March 11th, 2010 at 08:22:16.
Permalink | Comment | Email this
Arrays
10 Mar 2010 at 3:10am
You don't need to define separate fields for similar items in JavaScript, you can make them an array instead. Arrays are the most commonly used of the types of object built into JavaScript. In this twelfth tutorial on "Modern JavaScript" we look at the difference between Objects and Arrays.
Arrays
Arrays originally appeared on About.com Focus on JavaScript on Wednesday, March 10th, 2010 at 09:10:05.
Permalink | Comment | Email this
JavaScript Events
9 Mar 2010 at 2:26am
The main way of using JavaScript with a web page is to have pieces of JavaScript that run when specifiic events occur. There are a number of different types of event that can trigger the running of your JavaScript as well as several ways of attaching the JavaScript to the event.
JavaScript Events
JavaScript Events originally appeared on About.com Focus on JavaScript on Tuesday, March 9th, 2010 at 08:26:02.
Permalink | Comment | Email this
Light Mixer
7 Mar 2010 at 11:12pm
Some time ago I created a watercolour mixer script that allows people to see the effects of mixing watercolour paints on their computer screen. This was somewhat more complex than it might appear to be since paint and the light that the computer screens use do not work the same way with regard to mixing colours together. Following requests for a similar light mixer script that can be used to demonstrate just how differently lights mix together compared to paints I have now created a Light Mixer script that works identically to the watercolour script apart from using the additive primary and secondary colours instead of the subtractive ones.
Light Mixer originally appeared on About.com Focus on JavaScript on Monday, March 8th, 2010 at 05:12:51.
Permalink | Comment | Email this
The RegExp Object
7 Mar 2010 at 10:08am
There is more than one way to define a regular expression in JavaScript. Regular expressions are actually instances of RegExp objects at the nineteenth tutorial in the Regular Expressions series explains.
The RegExp Object
The RegExp Object originally appeared on About.com Focus on JavaScript on Sunday, March 7th, 2010 at 16:08:36.
Permalink | Comment | Email this
Breaking Text into Chunks
5 Mar 2010 at 10:49pm
Usually when writing something in code the text is broken up into a number of chunks each of which contains the same number of characters. There are of course other reasons why you might want to split up a string of text into a number of pieces that all contain the same number of characters. We can easily add our own method to JavaScript that will do this with just a couple of lines of code.
Breaking Text into Chunks
Breaking Text into Chunks originally appeared on About.com Focus on JavaScript on Saturday, March 6th, 2010 at 04:49:38.
Permalink | Comment | Email this