| JavaScript
Definition [1]
(Formerly LiveScript) Netscape's simple,
cross-platform, World-Wide Web scripting
language. JavaScript is an interpreted scripting
language developed to extend the functionality
of webpages and to provide a certain amount
of interaction with the website's users.
Structured much like many "Application Languages"
in terms of functions, properties, methods,
etc. JavaScript lent the web its first level
of "programming," even though it isn't
a programming language.
|
JavaScript
relies on C-based syntax which looks
much like:
Function funcName(param1,param2)
{
statement1;
statement2; }
|
JavaScript can be included on a web page
in one of the 3 ways: externally, in-page
and in-line. Externally means you have one
JavaScript file which you can call from
any of your web pages, an example:
|
Code in JS:
<script src="myJS.js"
language="javascript"></script>
|
Including your JavaScript in-page is often
done in the HEAD of your document, and allows
any part of that page to access the JavaScript
functions, methods and properties, and it
looks like this:
|
Code in JS:
<script language="javascript">
function someFunc()
{ window.alert('hello world');
}
</script>
|
Including your JavaScript in-line is often
the perfect solution for problems which
only need solving once, such as letting
a user know a certain piece of helpful information
when they click on a link:
|
Code in JS:
<a href="javascript:window.alert('This
is a helpful hint!);">?</a>
|
What It Really Is
JavaScript is a scripting language which
allows you to add interactivity to your
web page. If you have ever seen a clock
on a page, a scrolling status bar, a new
window open or had a web-form tell you some
information wasn't filled in properly, you
have already seen JavaScript. In the beginning,
JavaScript was used mainly for "toys," like
telling the user how long they had been
on the page. Increasingly though, it is
developing a place as an essential part
of any web-guru's toolkit. From the simple
things like form validation to the complex
things as drop-down menus; JavaScript is
showing that it has matured beyond the "toy
stage." In fact, you would be hard-pressed
to find a large site which didn't utilise
JavaScript in some respect.
Advantages
+ The ability to present information to
users as and when it is pertinent
+ The ability to add interactivity
+ The ability to utilise the space on
your pages more effectively
Disadvantages
+ The ability to present information to
users as and when it is pertinent
+ The ability to add interactivity
+ The ability to utilise the space on
your pages more effectively
|
Pop-Up Window
Script
Code in JS:
<html>
<head>
<script language="JavaScript">
<!-- hide from JavaScript-challenged
browsers function openWindow(url,
name) { popupWin =
window.open(url, name, 'width=400,
height=600, left=100, top=100')
}
// done hiding -->
</script>
</head>
<body onLoad="openWindow('myWin.html','newwin');">
</body>
</html>
|
|
Display an
alert to the user
Code in JS:
<script language="javascript">
window.alert ('You have selected an
invalid option');
</script>
|
|