JavaScript
Introducing Javascript
Javascript is a new technology even newer than java itself.Netscape initially developed javascript under the name of Livescript.The scripting Language was intended to extend the capabilities of basic HTML and provides an alternative to using CGI scripts.After Java’s popularity,Netscape followed the notation of Java – hence, the name change to JavaScript.
Features of JavaScript
Javascript is Embedded into HTML
If you deal with JavaScript ,there is hardly any separation of the two.Javascript code is usually housed within HTML documents and executed within them.Additionally, by itself, Javascript has no user interface; It relies on HTML to provide its means of interaction with the user.
Javascript uses HTML as a means of jumping into the Web application framework.It also extends the normal capabilities of HTML by providing events to HTML tags
Example for JavaScript embedded in an
HTML file
<html>
<head>
<title>Status Bar</title>
<script language="javascript">
window.defaultStatus="welcome to the large URL page."
function changeStatus(){
window.status="Click me to go to Acadia Software home page."}
function changeDefaultStatus(){
window.defaultStwindow.document.statusFooptions[window.document.statusForm.messageList.selectedIndex].text}
</script></head>
<body><p> </p><p> </p><p style="align:center;color: red;font-size: large;"><strong>http://www.yourwebsite.com</strong></p>
<p style="align:center;"><a href="http://www.yourwebsite.blogspot.com" onmouseover="changeStatus();return true">Go...</a></p>
<form name="statusForm" method="POST">
<p>
<br/>
<br/>
<br/>
</p>
<p style="align-content: center;">
<select name="messageList" size="1">
<option selected>Welcome to the large URL page.</option>
<option>This page intentionally left.</option>
<option>WEb page</option>
</select>
<input type="button" name="Change" value="Change" onclick="changeDefaultStatus()">
</p>
</form>
</body>
</script>
</head>
</html>
Output
Javascript
is Browser Dependent
Javascript is
but a scripting language, not a tool in and of itself. The software that
actually runs the Javascript code you write is the Web browser.Javascript
depends on the web browser to support it.If the browser does not support it,
your code will be ignored.Even worse, if you do not account for unsporting
browser, the javascript code itself is displayed as text on your page.
Commonly
available Browser are:
·
Netscape
Navigator
·
Microsoft
Internet Explorer
·
Sun's
Hot Java
Javascript
is an Interpreted Language
As with most
scripting languages, Javascript is interpreted at runtime by the browser before
it is executed.Javascript is not compiled into an actual program - like an .exe
file but remains part of the HTML document to which it is attached. The
disadvantage of an interpreted language is that it takes longer for the code to
execute because the browser compiles the instructions at runtime just before
executing them.However , the advantage is that it is much easier to update your
source code. you do not have to worry about old version of javascript script
hanging around because if you change it in your source HTML file ,the new code
is executed the next time the user accesses the document.
Javascript
is a Loosely Typed Language
Javascript is
far different from strong-typed languages such as Java or Delphi, in which you
must declare all variables of a certain type before using them.In contrast,
Javascript is much more flexible.You can declare variables of a specific type,
but you do not need to. you can also work with a variable when you might not
know the specific type before run time.
Javascript
is an Object-based Language
you might see
javascript referred to as an object-oriented programming(OOP) language by
Netscape and others, but this is actually a stretch of the true meaning of
OOP.Javascript is really an object-based language.
Javascript
is Event-Driven
Much of the
javascript code you write will be in response to events generated by the user
or the system. The javascript language itself is equipped to handle events.HTML
objects, such as buttons or text fields, are enhanced to support event
handlers.
Javascript
is Multifunctional
Javascript is
multifaceted and can be used in a variety of contexts to provide a
solution to a web-based problem.
Uses of
Javascript are:
v Enhance and liven static HTML pages.
v Develop client-side applications.
v Serve as a building block for client/server
web applications.
v Serve as a client-side glue between HTML
objects ,java applets, ActiveX controls and Netscape plug-in.
v Serve as an extension to a Web server.
v Provide database connectivity without using
CGI.
The
Javascript Language spans Contexts
Javascript is a
language, not a tool.As a web scripting language, it can be useful in a variety
of contexts. Much of the focus on Javascript by web developers is for
client-side scripting . However, you can also use it on the server-side in the
Netscape Livewire Pro environment and Microsoft's Activex server framework.It
is also used as the native language for Web development tools.
Four
Phases of the World Wide Web
Phase I: Character - Based Hypertext
Phase II: Graphical - Based Static HTML
Documents
Phase III: Dynamic HTML Documents
Phase IV: Active HTML Documents
HTML
HTML gives you the capability to create remarkable static
Web pages. Although these documents have been creative, interesting , and by
all means useful, Javascript gives you the capability to make these extensive
static pages interactive and more responsive to user actions and input.
Extending your HTML pages with Javascript puts more power
to your page and gives you more flexibility with what your HTML can
do.Javascript cannot standalone but is always tied to your HTML page and the
browser.Javascript is an interpreted language that is processed by the browser
when the page loads.
Javascript enables the web developer to create pages that
are more dynamic by embedding a scripting language in the existing HTML
structure. You can now but processes behind buttons, run calculations on
form-entered data, or perform actions when the user moves the mouse over an
HTML object.
Javascript offers advantage over client-based interactive
documents such as CGI because Javascript based documents are less dependent on
client-side processing , so they are quicker to respond to user interactions
and requests.
Embedding
Script
Javascript scripts
are integrated into HTML using the HTML <script> and </script>
tags, Both the start and end tags are required for <script>, and at the
current time , the language attribute and source attribute are the only
attributes currently available.Language is used to specify the scripting
language in which the script is written , and source (SRC) is used to specify
the filename of the Javascript statements, if they are stored in a separate
file.
Method
1:
<script
language="javascript">Script language</script>
Method
2:
<script
language="javascript">
function
options()
{
document.write("embedding
the code")
}
</script>
Example
<html>
<head>
<title>Example></title>
<script
language="javascript" for="window"
Event="onLoad()">
alert("Hello");
</script>
</head>
<body>
</body>
</html>
Method
3
<script
language scr="filename.js">
</script>
Example
<script
src="myscript.js"></script>
Type
the following code in a file called myscript.js
document.write("calling
from a separate file")
When you load the
script from another file , the language attribute is not necessary as long as
you use the correct .js extension.Using
this methodology , you have the capability to modify your Javascript code without
ever opening and risking unwanted changes to your HTML pages.
Generating
HTML
The example given
below tells you to generate HTML pages from Javascript.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Using Javascript to create HTML tags</title>
</head>
<body>
<script>
document.write("<h1>Hi web surfers!</h1>")
document.write("<p>Welcome to <cite>Javascript</cite></p>")
</script>
</body>
</html>
Output

No comments:
Post a Comment