Globale linker

Book 1

Book 2

Book 2 Ch. 2 JavaScript Fundamentals

JavaScript is a client-side scripting language that was developed by Netscape as an extension to HTML to allow designers manipulate Web page elements simply and easily. JavaScript will run in both Netscape and Microsoft browsers.

JavaScript provides several benefits to the web programmer, including short development cycle, a mild learning curve and platform independence.

JavaScript allows you to create web pages that interact with your users, based on their keyboard and mouse inputs. JavaScript functionality includes:

In JavaScript attributes and behaviors are called properties and methods. Properties represent various attributes of the object, such as height, color, size... and methods are the actions an object can be made to perform, such as calculation, onscreen movement or the writing of text.

VBScript is a scripting language developed by Microsoft, and is a subset of Visual basic programming language. Will not run in Netscape browsers.

JScript is Microsoft's implementation of JavaScript. Several minor differences exist between the two, that results in that it will probably not run in Netscape browsers.

ECMA Script is a standardized scripting language.

JavaScripts are embedded into the HTML code with the HTML tag <script>.

<html>
<head>
<title>Page title</title>
<script language="JavaScript">
<!--
JavaScript code goes here
//-->
</script>
</head>
<body>
Page content
<script language="JavaScript">
<!--
JavaScript code goes here
//-->
</script>
</body>
</html>

The language attribute of the <script> tag tells the browser which type of script it is about to read. If you do not add the language attribute, the default scripting language in both NN and IE is JavaScript.

Notice that the comment tag <!-- is used to «comment out» or hide text in the script. You can add this in case a user browsing your pages has an old browser that is incapable of interpreting JavaScript.

Dot notation is used to associate an object's name with its properties or methods.
objectName.objectProperty
objectName.objectProperty = value
document.bgcolor = "#FFFFFF"

Communicating with the user is done with the following methods:

Concatenation is used in JavaScript to combine text strings by adding them together with the + sign.
alert('Hello ' + prompt('What is your name',''));

New windows are opened with the open() method.

open("URL","windowname","featurelist")
open("http://www.donald.no","donald", "width=600,height=400,scrollbars=1")

The feature list contains a series of attributes that you specify as either displayed or not. The accepted values for these are 1 (or yes) and 0 (or no).

A function is a set of JavaScript statements, that performs a specific task. The function can be called upon by user actions or in other functions.

See the JavaScript tutorial for further information.

Chapter 1 Book 2 Chapter 3 Book 2