Sunteți pe pagina 1din 11

JavaScript

Netscape Navigator v. 2 provided client-side scripting with


JavaScript
JavaScript was developed by Netscape under the name
LiveScript

Sun and Netscape decided to put the word ’Java’ into


LiveScript changing the name to JavaScript (marketing...)

Syntax similarities between Java and JavaScript existed


before the name change

Internet Explorer (IE) 3 provided VBScript and JScript


(almost 100% compatible with JavaScript in Navigator 2)
JavaScript and Support for It
Important to distinguish programming language from
DOM: programming language provides data types,
variables, control structures etc., and is independent from
DOM (this is core JavaScript).

To ensure compatibility between Microsoft’s and


Netscape’s versions of JavaScript both companies worked
with the European Computer Standards group. The work
resulted in ECMA-262 (known as ECMAScript)

Both Netscape 4 and IE4 implement ECMAScript


The core JavaScript in Navigator 4 (JavaScript 1.2) is
supported by JScript in IE4 almost completely
Support for DOM via JavaScript
Navigator supports CSS1, but sheets are not very
dynamic: can not change style and properties of content
already loaded into the browser (to change color of a block
of text, need to create content for each color as a separate
positioned element and then show and hide these
elements dynamically)
Navigator supports CSS-P
Navigator also provides an alternative to CSS-P in the
form of <LAYER><LAYER/> tag. Each layer is a holder for
content that exists in its own plane suspended above the
main document and independent of the main document
and other layers. New layers can be created after a page
has been loaded using JavaScript.
Support for DOM via JavaScript
For portability Netscape treats a positionable elements
defined via CSS-P syntax or the <LAYER> tag as the
same kind of object

Netscape capabilities to produce content dynamically are


quite limited. All it can do is: swap images in place, load
new content into a layer, set location of a positionable
element.
Support for DOM via JavaScript
IE4 provides many facilities for modifying content of a
page after the page has been loaded. Virtually every
element defined by HTML is exposed to scripting.

IE4 supports W3C’s recommendation on CSS1 almost in


its entirety

IE4 not only supports CSS-P, but also allows you to apply
CSS-P attributes to individual HTML elements (can assign
visibility and position to an image even if it is not
surrounded by <DIV> or <SPAN> tag)
Support for DOM via JavaScript
IE’s rendering engine is capable of quickly re-rendering
modified HTML content (unlike Netscape’s rendering
engine). Therefore, most properties can be changed on
the fly: can increase the size of text within <H3></H3>
tags to <H1></H1>.

Both Netscape and IE4 bubble events


(see bubble-event.html example)
Cross-Platform Strategies
Page Branching
server determines browser type/version and serves appropriate page
(can use CGI and other server-side technologies)
browser first loads an HTML page with unscripted content and a script
that can load proper scripted page based on the browser type/version

Internal Branching
see internal-branching.html example (look at the page source inside
browser)
Common Denominator Design
use only features supported by ALL major browsers

Custom API
design a set of library functions (in JavaScript) and reference them from
all HTML files. each function contains code for Netscape and IE4 and
extends the vocabulary of the language.
Cross-Platform Strategies
What’s the best strategy?
Limitations of JavaScript
Can not do anything beyond HTML- and browser-related
tasks

Does not have any graphics capabilities

Can’t read from or write to files (security restrictions)

Does not support networking (but can make a Web


browser download an arbitrary URL)

Does not have multithreading capabilities


What JavaScript Can Do
Can write arbitrary HTML into the document

Can generate documents from scratch

Can control browser


open new windows, change appearance of windows, access history and
move forward and backward, display messages in the status line)

Can interact with forms (check and set fields)


seeform-validate1.htmlexample
What JavaScript Can Do
Can interact with the user
see form-validate1.html example above

Can read and write client cookies


seesetcookie.htmlexample
seereadcookie.htmlexample

Can interact with Java applets and plug-ins (part of


Netscape’s LiveConnect)

S-ar putea să vă placă și