JavaScript – 1.1JScript – 2.0Internet Explorer – 4.0Netscape version – 3.0Opera browser – 3.0 JavaScript syntax: The void operator is used to allow the operand to be evaluated in the nor
Trang 1Property/method value type: Number primitive
The vertical position of the object in the display measured in pixels You can use the x and y ordinates of the object as targets of the scrollTo() method for the window it lives in
co-Warnings:
❑ This is withdrawn from Netscape 6.0 and no longer supported
URN (Definition)
A Uniform Resource Name
The URN notation is an alternative means of formatting the URI portion of a URL This is astandard which is in the process of being defined and deployed Details are available in RFC 2141.The format is somewhat different to that of a URL placed in an HREF=" " HTML tag attribute
It is not at present widely supported in browsers but may be in the future
User-generated object (Definition)
An object created under script control
JavaScript allows the user (or script developer really) to create their own objects, properties andmethods The prototypes for existing built-in objects can also be extended by the script developer.This has generally been supported since the earliest versions of the main JavaScript interpreters Itwas made available in the WebTV platform effective from the Summer 2000 release This meansthat DHTML effects created by authoring tools such as DreamWeaver should work better inWebTV boxes that are shipped after this date or are upgraded in the field
Trang 2userDefined object (Object/DOM)
You can define your own objects in several different ways
JavaScript – 1.5JScript – 5.0Internet Explorer – 5.0Netscape version – 6.0
JavaScript syntax:
Aside from the ways in which you can create custom objects with your own constructor functions,you can also create your own HTML tags to make custom document elements
Objects are instantiated from HTML tags and assume a class name from the HTML tag names in thedocument So you can invent your own tags that become objects in the document model in MSIE,and inherit some basic capabilities from the environment Netscape version introduces this
functionality at version 6.0
userProfile object (Object/JScript)
An object that encapsulates a user's profile within the system
Internet Explorer – 4.0
Object methods: addReadRequest(), clearRequest(), doReadRequest(),getAttribute()
Through this object, a script can access details about the user from the profile that the system maintains.This is accomplished by the arcane method of queueing requests for access Then having queued allthe requests, you can ask the user for permission with a single dialog
If the user grants permission, you can then access the userProfile values, after which the requestqueue can be cleared
Warnings:
❑ This is a not fully supported on some versions of MSIE for Macintosh
userProfile.clearRequest(), userProfile.doReadRequest(),userProfile.getAttribute()
Trang 3Method JavaScript JScript N IE Opera Notes
This method adds a request to the queue Each request denotes the parameters within the userprofile that the script needs to access You may call this method several times, each time asking for
a different user preference You won't initially be granted access to them until you have executedthe doReadRequest() method If the user affirms that you can access these values, then on itsreturn, you can use the getAttribute() method to access the value you need You can onlyaccess values you have requested and which the user has affirmed
Here is a list of all the user preference attributes that you can request:
Trang 4userProfile.clearRequest() (Method)
Clear all read requests from the queue
Availability: JScript – 3.0
Internet Explorer – 4.0
You should use this as soon as you have retrieved the necessary user information It purges allpending requests If you don't use this call, then if you made some more requests, next time youcall the doReadRequest() method the user is asked for permission to access an ever increasinglist of preferences
userProfile.doReadRequest() (Method)
Execute the current queue of read requests, asking the user for permission to access these
properties of the profile
IE navigator.userProfile.doReadRequest(aCode, aName,aDomain, aPath)
JavaScript syntax:
IE navigator.userProfile.doReadRequest(aCode, aName,aDomain, aPath, anExpire)
Trang 5aCode The use code selects an explanatory message
aDomain A server domain
aName A name denoting who is asking
anExpire An expiry date for the permissions
Argument list:
aPath A document pathHaving queued some requests to read user preferences of course you would only request access toones you genuinely needed Then you should call this method It presents the user with a dialogasking for permission to access the listed preference values If the user decides to grant access, youwill have access to the user preferences, but only to the ones you have requested
There are a set of optional parameters for this method although the first argument is mandatory.These arguments are:
❑ A usage code This is a numeric value but it is translated into an explanatory text in the dialogpresented to the user This argument must be present
❑ The name argument is available so that you can say who you are, when you ask for the permission toaccess the user profile
❑ You can specify a server domain, so that the permission granted can be recorded for that domain, tosave requests from that domain interrupting the user to ask for the same permission more than once.This lasts for the session or until the expiry date if it is set
❑ You can specify a document path within which permission granted will apply This is much like theway that cookies are allowed to be returned only for documents within a path tree This lasts for thesession or until the expiry date if it is set
❑ The last optional argument is an expiry date up to which time the permissions will be cached andcan be used again subject to the domain and path criteria being satisfied
Here is a list of the usage codes for use with the first argument:
7 Linking to other information already collected
9 Disclosure to other parties for reasons of updating the site
10 Disclosure to other parties for marketing purposes
11 Disclosure to other parties for marketing purposes with your permission
12 Disclosure to other parties for any other purposes
Trang 6userProfile.getAttribute() (Method)
Get an attribute of the vCard object
Internet Explorer – 4.0
Property/method value type: String primitive
If the user grants access to the userProfile data, this method will return the contents of thenamed attribute The same attribute names that were used when the request was queued should beused here These are all member attributes belonging to the vCard object
You should call this method once for each attribute you need If you have not been granted access
to any attribute you will simply receive a null value
Universel Temps Cordonne
time adjustment, Universal coordinated timeUtility objects (Definition)
Netscape Enterprise Server provides server-side utility objects to give assistance when runningserver-side JavaScript
Refer to:
Netscape Enterprise Server
Trang 7Value of an expression (Definition)
The result obtained by evaluating an expression
Value preserving (Definition)
The act of converting values from one data type to another should preserve the value with no loss
of resolution
Value property (Definition)
A property value of an object
A value property returns a generally constant value Examples are the NaN and Infinity valuesreturned by core objects
V
Trang 8❑ Do not create your own object properties with the same name as internal or core value properties Ifyou do, unpredictable behavior may result Internal values should be protected against accidentaldamage in this way and they would be, if the interpreter designers were infallible Unfortunately, todate, they have proven to everyone's dissatisfaction that infallibility is a lost art
Cross-references:
ECMA 262 edition 2 – section – 15.1.1
ECMA 262 edition 3 – section – 15.1.1
valueOf() (Method)
Returns the primitive equivalent value of the receiving object
JScript – 3.0Internet Explorer- 4.0Netscape version – 3.0
The primitive value of the receiving object is returned by this method
This method is supported by virtually all objects due to the fact that it is available as a method ofthe Global object in Netscape Therefore it is inherited into the scope chain for every script andfunction (method)
Host implementations will generally override this inherited support and provide specializedoutput routines that yield a reasonable value
Most likely the value will be a String primitive but it need not be It could be any of the built-incore primitive data types as specified in the ECMA-262 standard
Date.valueOf(), Number, Number.valueOf(),Object.valueOf(), String.valueOf()
Trang 9var (Declaration)
A variable declarator
JavaScript – 1.0JScript – 1.0Internet Explorer- 3.02Netscape version – 2.0Netscape Enterprise Server version – 2.0Opera browser – 3.0
- var anIdentifier = anInitialVaue
- var anIdentifier = anInitialVaue,
anInitialVaue An initial value for the variable
The var keyword prefaces a list of variable declarations The list is terminated by a semi-colon.Variables can be initialized in the declaration list that can declare a single variable or several at once
If the var statement occurs inside a function declaration, the variables are defined with a scopethat is local to that function body Otherwise they are defined with global scope and are created asmembers of the Global object When they are created as global variables, they take on the
DontDelete property attributes
Variables are created when an execution scope is entered A block does not indicate a new
execution scope, so variables cannot be created local to a code block unless it is a function body.That means they are not local to an if(), while() or for() block of compound statements.When variables are created, they are initialized to contain the value undefined If an initializer isadded to the variable declaration, the value is assigned when the var statement is executed, whichmay be some time after the execution scope has caused the variable to be created
Warnings:
❑ If you fail to declare a variable with the var keyword, you will end up creating a global variableautomatically If the variable should only have local scope and duration within a function, then youmay want to avoid this
❑ You should use local variables as often as possible to avoid unwanted side effects
Trang 10See also: = (Assign), Assign value (=), Assignment expression, Assignment operator,
Comma operator (,), Compound statement, function( ) , Global object,Initialisation, Semi-colon (;), Statement, Variable Declaration, Variablestatement
Cross-references:
ECMA 262 edition 2 – section – 10.1.3
ECMA 262 edition 2 – section – 12.2
ECMA 262 edition 3 – section – 10.1.3
ECMA 262 edition 3 – section – 12.2
VAR object (Object/HTML)
An object representing the HTML content delimited by the <VAR> tags
Availability: JavaScript – 1.5
JScript – 3.0Internet Explorer- 4.0Netscape version – 6.0
Trang 11HTML syntax: <VAR> </VAR>
anElementID The ID value of the element required
anIndex A reference to an element in a collection
Argument list:
Event handlers: onClick, onDblClick, onDragStart, onFilterChange,onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown,
onMouseMove, onMouseOut, onMouseOver, onMouseUp,onSelectStart
onClick 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonDblClick 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + Warning
onKeyDown 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonKeyPress 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonKeyUp 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonMouseDown 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonMouseMove 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonMouseOut 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonMouseOver 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonMouseUp 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + Warning
-Inheritance chain:
Element object, Node object
Variable (Definition)
A named storage receptacle for script accessible values
Availability: ECMAScript edition – 2
Variables are containers with names that you can manage from your JavaScript code You can createnew ones when you need to, and change the values that are stored in them whenever you want.Some variables are available only within the function block that is currently executing while others areavailable all the time The first kind are called local variables and the second are called global variables.The availability of a variable is determined by the scope chain rules that are in force at anyparticular time
Trang 12When a primitive value is stored in the variable, a unique copy of that value is associated with thevariable However, when an object is stored in a variable, the variable contains only a reference tothe object The object's reference count is incremented and is only decremented when a reference to
it is discarded To discard the reference to an object that is contained in a variable, it must bedeleted explicitly This will not affect the object but will reduce its reference count by one When itsreference count is zero, the object can be purged from memory Whether that happens or notdepends on the way that garbage collection is managed It is possible that simply replacing anobject reference with some other value may not properly decrease the reference count in someimplementations This can lead to a memory leak
Example code:
// Simple variable declaration
var myVariable;
// Declare and initialise a variable to a null value
var emptyVar = null;
// Declare and initialise to a floating point value
var priceData = 11.50;
// Assign a string value to a variable
someString = "23 The Irons, Cleethorpes";
// Assign a boolean value to a variable
// Use an unusual variable identifier name
$_funnyVarName = "Be careful with var names";
// Declare and initialise several variables on one line
var aaa = 1, bbb = 2, ccc = 3;
// Store an object reference in a variable
myObject = new Object();
See also: Constant, Function arguments, Garbage collection, Memory leak, Reference
counting, Scope, Scope chain
Cross-references:
ECMA 262 edition 2 – section – 7.5
ECMA 262 edition 2 – section – 10.1.3
ECMA 262 edition 2 – section – 12.2
ECMA 262 edition 3 – section – 7.6
Trang 13ECMA 262 edition 3 – section – 10.1.3
ECMA 262 edition 3 – section – 12.2
O'Reilly JavaScript Definitive Guide – page – 52
Wrox Instant JavaScript – page – 13
Variable Declaration (Definition)
Variable declarations are stored as properties in an object
Availability: ECMAScript edition – 2
To create a variable called myVariable, you need to place a declaration like this in the scriptsource text:
var myVariable;
You can optionally assign an initial value to the variable as it is declared Like this:
var myVariable = "Initial value";
The semantics of the ECMAScript standard dictate that variable declarations must follow FunctionDeclarations and Formal Parameter List processing
The initial value of variables as they are declared is set to undefined Any attributes of the property
in the variable object are defined by the type of code If a variable already exists and a declarationduplicates the same identifying name, the present value will not be replaced by the undefinedvalue In particular, a variable declaration cannot replace a previously declared function definition
or formal parameter name
See also: Declaration, Definition, Formal Parameter List, function( ) , Script Source Text,
var, Variable instantiation, Variable statement
Cross-references:
ECMA 262 edition 2 – section – 10.1.3
ECMA 262 edition 3 – section – 10.1.3
O'Reilly JavaScript Definitive Guide – page – 53
Trang 14Variable instantiation (Definition)
Variables are local to one execution context
Availability: ECMAScript edition – 2
Every execution context has its own variable object associated with it Variables declared in thesource text are added as properties to the variable object
This mechanism is a way of making sure that variables that are local to one execution context, donot affect the values of variables in another
In the case of global and eval() code, any functions that are declared in the script source text arealso added as properties of the variable object JavaScript 1.3 and ECMAScript edition 3 introducesnested functions which means they will be added too
For function, anonymous, and implementation-supplied code contexts, any passed in arguments(parameters) are also added as properties of the variable object
Which particular variable object is used, and what attributes its properties take on depends on thetype of code
See also: Execution context, Formal Parameter List, function( ) , Script Source Text,
Variable Declaration
Cross-references:
ECMA 262 edition 2 – section – 10.1.3
ECMA 262 edition 3 – section – 10.1.3
Variable name (Definition)
The name of a variable that is unique within a block but not necessarily within the scope chain
See also: Variable, Identifier
Cross-references:
Wrox Instant JavaScript ISBN 1-861001-27-4 – page – 14
Variable statement (Definition)
A variable statement uses the var keyword to preface a list of variable declarations
Availability: ECMAScript edition – 2
Trang 15A variable statement uses the var keyword to preface a list of variable declarations The statement
is terminated with a semi-colon
You can declare the variables one at a time or several at once with the same var statement.When the variables are declared, an initial value can be assigned to them at the outset
Variables can be declared inside a function body When they are declared there, they become localonly to that function When the function exits, the execution context is popped off the scope chainand the variables are discarded
Variables can also be declared and assigned within a for loop header block
See also: = (Assign), Assignment expression, delete, Statement, var, Variable
Declaration
Cross-references:
ECMA 262 edition 2 – section – 10.1.3
ECMA 262 edition 2 – section – 12.2
ECMA 262 edition 3 – section – 10.1.3
ECMA 262 edition 3 – section – 12.2
VBArray object (Object/JScript)
A special JScript object for interacting with Visual Basic or VBScript array data
Availability: JScript – 3.0
Internet Explorer- 4.0
JavaScript syntax:
Argument list: aVisBasArray An array created inside Visual Basic or VBScript
Because VBScript is only available on the Windows platform, this object has limited use in
portable applications
You might find it useful in an intranet scenario where you have total control over which browsersare deployed to the users In that case, you know that your pages will be viewed on a compatibleplatform and can happily use this object with impunity
Warnings:
❑ Because the Visual BASIC interpreter is only available on a limited number of platforms, thisfunctionality is likely to be limited only to those pages that need to work on the MSIE browser in aWindows environment This technique is unlikely to work in any other context
Trang 16VBScriptThis constructor would be useful if you are interacting with Visual Basic scripts or functions thatneed to have an array passed to them.
Trang 17VBArray.dimensions() (Method)
A method for requesting the number of dimensions of the array
Internet Explorer – 4.0
This tells you the number of axes in the array; you can then determine the maximum size they areexpected to occupy with the lbounds() and ubounds() methods
Argument list:
anIndexN As many dimensions as are required to address the
required itemThis acessor method is used to extract the values from cells within the array You cannot addressthe cells directly as you would with a native JavaScript, array although you can convert the
VBArray to a native JavaScript array Be careful though with multi-dimensional arrays
You can use the dimensions() method to find out how many axes there are for addressing amultidimensional array The lbounds() and ubounds() methods can be used to determine theextent of those axes
VBArray.lbound() (Method)
A method that returns the index position of the first element in the VBArray
Internet Explorer – 4.0
requiredThis is the lower boundary value for the indicated dimension You will need to measure this foreach dimension individually if the array is multi-dimensional
Trang 18VBArray.toArray() (Method)
A conversion method for creating a JScript array object from a VBArray object
Internet Explorer – 4.0
You can convert an entire Visual Basic array to a JScript array It is possible some data will get lostalong the way but simple data formats should survive the translation
Multi-dimensional arrays consume a great deal more memory than you anticipate The
compounded effect of adding each dimension usually increases storage by at least an order ofmagnitude each time
VBArray.ubound() (Method)
A method that returns the index position of the last element in the VBArray
Internet Explorer – 4.0
required
This is the upper boundary value for the indicated dimension You will need to measure this foreach dimension individually if the array is multi-dimensional
vCard object (Object/JScript)
This is an object accessible only through the user preferences interface in the MSIE browser
Internet Explorer – 4.0The vCard object is the parent object that contains all the user preferences settings
Trang 19There are basically three kinds of properties:
❑ Those that are members of the vCard.Business object
❑ Those that are members of the vCard.Home object
❑ Those that are members of the vCard object directly
Here is a list of all the user preference attributes that you can request:
Trang 20Version History (Background)
Historical details of JavaScript versions
See also: JavaScript version, JScript version, History
view-source: URL (Request method)
You can use this for debugging in both Netscape and MSIE
This is a useful debugging aid in some circumstances Sometimes it is hard to download a file andthis may give you a workaround
To display a window containing the HTMLized version of a directory in the client machine, try this:view-source:/
It works at least on Netscape Navigator version 4.7 on a Macintosh It likely works on other
platforms and versions of Netscape too
The top level directory is the folder in which Netscape lives
On a Macintosh at least, you can append a disk volume name, like this:
Trang 21Visual filters (Definition)
The MSIE browser in version 4.0 and upwards now supports visual transition effects to use whenmodifying page content or navigating from page to page
These filters have been enhanced and added to at version 5.0 and 5.5 of JScript As of version 5.5 ofMSIE, the performance of these filters is also optimized and enhanced
The following kinds of visual filters are supported:
Force an undefined value to replace an operand
JavaScript – 1.1JScript – 2.0Internet Explorer – 4.0Netscape version – 3.0Opera browser – 3.0
JavaScript syntax:
The void operator is used to allow the operand to be evaluated in the normal way (perhaps it is anexpression or function call), but to force an undefined value to be returned in its place
A very useful place for this is when you create JavaScript: URLs Making sure the result of theexpression is void helps the browser cope with the fact you are calling a script and not fetching adocument Don't use void however if you want the result of the JavaScript execution to be used asthe content of a window
This shows how to use void in a click handler:
<a HREF="javascript:void(callHandler('testString'));">
Trang 22This shows how to force JavaScript result data into a window:
<a HREF="javascript:'<HR>Some text here</HR>'">
You can also use the void operator to manufacture an undefined value in older browsers that have
no keyword already defined The expression (void 0) is just such a value This is unnecessary nowthat JScript 5.5 supports an undefined value in compliance with ECMA edition 2
The associativity is from right to left
Refer to the operator precedence topic for details of execution order
This keyword also represents a Java data type and the void keyword allows for the potentialextension of JavaScript interfaces to access Java applet parameters and return values
This technique is also useful if you want to evaluate an expression merely for the benefit of its sideeffects and without any interest in the value it returns
See also: Assignment expression, Associativity, javascript: URL, LiveConnect, Operator,
Operator Precedence, typeof, Unary expression, Unary operator, undefined
Cross-references:
ECMA 262 edition 2 – section – 11.4.2
ECMA 262 edition 3 – section – 11.4.2
Wrox Instant JavaScript – page – 21
Trang 23void expression (Definition)
An expression whose value is discarded and is evaluated purely for its side effects
See also: Constant expression, Conversion, Side effect
volatile (Reserved word)
Reserved for future language enhancements
The addition of this operator suggests that volatile identifiers may be supported in a later version
of the ECMAScript standard
See also: const, Reserved word
Cross-references:
ECMA 262 edition 2 – section – 7.4.3
ECMA 262 edition 3 – section – 7.5.3
Trang 24This is a popular standard for use in mobile computing devices It uses a derivative of the
JavaScript standard language called WScript This is constructed within a framework called WML,which is built around a structure organized like a stack of cards rather than pages, although thelinkages between them are similar
At the time of writing, this standard has become somewhat popular but there is already talk of itonly being a transitory system Future mobile computing devices may use something moresophisticated and therefore WAP may become less popular Ultimately it will be made obsolete by
aHandler A handler that gets called when the property changes
❑ Property name
❑ Old value
❑ New value
Trang 25It gets an opportunity to modify the new value or veto the change by returning the old value.Whatever value is returned is stored in the property You can carry out other JavaScript tasksduring this property call, although it is probably best to avoid making changes to other propertyvalues with watch-points that call the same handler, because you could set up a recursive loop.
If you invoke the watch() method without specifying a receiving object, as if it were a function,you are actually setting watch-points on global object properties Since this is where global
variables live, you can monitor them as easily as object properties
The new event model supported by Netscape 6.0 and that already available in MSIE 5.0 present apropertyName property that belongs to the Event object You can inspect that during an
onPropertyChanged event and achieve the same watch()/unwatch() behavior
// Code works with Netscape 4+ only
// Define initial value for property
var XXX = 10;
// Define watch handler function
function watchHandler(aProp, anOldVal, aNewVal)
See also: Event, Event handler, Event management, Event model, Event object,
onPropertyChange, unwatch(), Watchpoint handler
Trang 26Wrox Instant JavaScript – page - 56
Watchpoint handler (Interface)
The handler that is connected to a watch point has a special pre-defined API specification
someCode; return actualVal}
actualVal The value that will be placed into the property
anId A name for your handler function
aProp A formal parameter to pass the property name in
newVal A format parameter to pass the new value in
Argument list:
oldVal A formal parameter to pass the old value in
Your handler function is passed to the watch() method belonging to the object whose propertyyou want to monitor
When that property changes, your handler will be called
You will be passed the following:
❑ The property name
❑ The old value
❑ The new value
Whatever you return from this handler will be stored in the property and will become its newvalue This means you can return the old value, forcing the property to be read-only You mightchange the new value to something else Perhaps you would force the value to be all uppercaseregardless of how it had been specified You may even want to display an alert to warn theoperator that the property is being changed
Trang 27.web (File extension)
A compiled JavaScript and HTML application for Netscape Enterprise Server
Web browser (Definition)
A web browser can be used on a desktop computer, mobile device or TV set-top box to view web pages.When JavaScript is built into a web browser, the interpreter is an integral part of the application.However, it is technically possible to separate the JavaScript interpreter and provide it as a servicethat is available to all applications in the system This seems to be the way that JScript is going onthe Windows platform Whether the browser-based script environment is truly sharing the
Windows Script Host facilities may depend on the browser version being used
A web browser based interpreter will execute JavaScript that is provided in the following
containers:
❑ An HTML page
❑ A JavaScript include (.js file)
❑ A Java archive (.jar file)
To add JavaScript to your HTML pages, you need to add <SCRIPT> tags as containers for the scriptsource text
See also: jar, java, js, <SCRIPT>, Host environment, HTML, HTML file, iCab, Image object,
Image(), Image.Class, Internet Explorer, Netscape Navigator, OpenTV, Opera,Platform, WebTV
Cross-references:
Wrox Instant JavaScript – page - 5
Wrox Instant JavaScript – page - 41
Web scripting (Definition)
Web browsers provide a host environment for client-side computation
Availability: ECMAScript edition - 2
Trang 28Web browsers provide a host environment in which to view a web page downloaded from a remoteserver or from a local file system Scripts running in that browser use an object model
representation of the browser and the presently viewed document These are called the BrowserObject Model and the Document Object Model respectively There are objects to represent
windows, dialog boxes, alerts, text areas, anchors, frames and all the functionality that the browserprovides through its graphical user interface
The host environment provides a means of connecting events to scripts and those scripts are thentriggered when the user interacts with the document or browser Because the entire complexprovides a framework for execution and that execution is event driven, there is no main() function
as you would have with the C language for example
JavaScript that executes in the browser is called client-side script code Similar script code can beexecuted in the web server as part of the web page request-response loop That code would
generally be executed in a more serial fashion in response to a single event (generate a page) Thissort of activity is called server-side scripting
A complete web-based application can be built with code distributed between the server and clientenvironments
Cross-references:
ECMA 262 edition 2 – section - 4.1
ECMA 262 edition 3 – section - 4.1
Web server (Definition)
An application that delivers web content on request from a browser
There are many web server products available Here are a few:
Apache At the time of writing it is currently at version 1.3.12 although minor updates
happen all the time The version 2.0 of Apache is now being seeded for betatesting
Enterprise Server A Netscape server product
Fnord A free web server that runs on Windows platforms
IIS Internet Information Server A Microsoft product
Intrabuilder A Borland server product
PWS Personal Web Server A Microsoft product
WebSite A commercial PC-based web server
WebStar A Macintosh-based web server
Cross-references:
Wrox Instant JavaScript – page - 5
Trang 29WebTV (TV Set-top Box)
An analogue interactive TV set-top box
Set-top boxes fall into several categories From the point of view of a JavaScript developer, the mostimportant category is the 'Browser in a box' model This takes a basic Netscape Navigator or MSIEbrowser, places it inside a modest functionality PC and allows its page content to be overlaid ontop of the video that is broadcast off-air The video can also be placed into a cell within the page toallow the web page to be placed behind the video
This is generally accomplished by allowing the <IMG> tag to take its source from a new URL type.Instead of an HTTP: protocol, the TV: protocol is used to trigger the video overlay hardware inplace of a web request
The WebTV boxes have been available for several years and are an analogue TV-set top box.The JellyScript interpreter used in the WebTV box underwent an upgrade in late Spring 2000 and wasreleased for public use during the Summer It is generally referred to as the Summer 2000 release Youshould be somewhat careful with releases of interpreters in set-top boxes, as a new release is likely to
be presented for each manufacturing run These will generally contain only minor changes The top boxes are also designed to allow the interpreters to be upgraded remotely when they connect.This can lead to some interesting problems if you connect a UK PAL compatible box to an AmericanNTSC service because the video hardware is reconfigured and is then rendered unusable
set-The integration of the web content with the TV service is by means of crossover links that are URLvalues embedded into the video signal on a very low data rate channel that is part of the closedcaptioning signal
The URL is encoded with a checksum and arrives at a rate of about 100 characters per second.Because the transfer is at such a low bit rate the URL values need to be short When the box detects
a cross-over link, it displays a small icon in the top right of the screen and the user can elect torequest the associated page The box then dials an ISP and the page is delivered in the normal way.This is a quite good and workable enhancement to the TV service and although its deployment islimited mainly to the United States, boxes have been trialled in Europe and elsewhere
There are a few limitations imposed on the JavaScript supported by the box and the embeddedbrowser does not generally support extensions such as Java, plugins and ActiveX but neverthelessyou can still accomplish quite a lot
See also: ATVEF, Interpret, JellyScript, Microsoft TV, Platform, Script execution, TV Set-top
boxes, Web browser
Cross-references:
http://developer.webtv.net/authoring/javascript/javascript.htm
Trang 30Week day (Time calculation)
A value between 0 and 6
Calculating weekdays is a simple modulo and offset of the day number derived from the time value.The formula for calculating day number is shown here:
t = an instant in time measured in milliseconds relative to 01-January-1970 UTC.msPerDay = 86400000
Day(t) = floor(t/msPerDay)
WeekDay(t) = (Day(t) + 4) modulo 7
The resulting values will be from 0 to 6 with Sunday being represented by 0 and Saturday by 6
By way of proof, WeekDay(0) should yield 4 which represents Thursday, 01-January-1970
Example code:
// Grab the time now in milliseconds
myMilliseconds = new Date().getTime();
// Work out the week day number based on a thursday start
// This should be equivalent to Date.getDay()
Trang 31ECMA 262 edition 2 – section - 15.9.1.6
ECMA 262 edition 3 – section - 15.9.1.6
An iterator mechanism – a loop construct
JavaScript - 1.0JScript - 1.0Internet Explorer - 3.02Netscape - 2.0
Netscape Enterprise Server version - 2.0Opera - 3.0
- while ( aCondition ) { someCode }
someCode The code that gets looped
Although the while() statement is an iterator, it is functionally related to the if() statementsince it will execute the statement block only as long as the condition evaluates to true
The difference between if() and while() is that if() only processes the statement block oncewhereas while() processes the statement block repeatedly until something causes the conditionenclosed in parentheses to evaluate to false
A while loop tests the condition before execution of each pass through the loop If a do loop issupported by the implementations, it would test the condition after each pass through the loop
A break statement can be used to terminate a while() iterator prematurely, perhaps within aconditional test that is supplementary to the one in the while() heading
Trang 32A continue statement can be used to initiate the next cycle of the while() iterator.
The unlabeled form is more commonly used and was available from earlier releases of the
JavaScript and JScript interpreters Labeling was added later at version 1.2 but is not often used
If a labeled continue is used, the condition is tested again, and the loop will cycle if necessary
Warnings:
❑ Make sure that something in the statement block will cause the test condition to change tofalse otherwise you will create an endless loop that can never exit How this is dealt withdepends on what you are doing in the loop and whether the implementation can detect anendless loop situation It is likely the process containing the JavaScript interpreter will eitherstall and hang or a runtime error may result In extreme cases, the hosting application maycrash and on some platforms, the entire system may halt At the very least, you could expectmemory and CPU usage to go up while the loop runs On a multi-user system, you may be able
to use an administrator account to kill the offending process
See also: break, Compound statement, continue, do while( ), Flow control,
for( ) , for( in ) , if( ) , Iterationstatement, Label, Obfuscation, Off by one errors
Trang 33ECMA 262 edition 2 – section - 12.6.1
ECMA 262 edition 2 – section - 12.7
ECMA 262 edition 2 – section - 12.8
ECMA 262 edition 3 – section - 12.6.2
Wrox Instant JavaScript – page - 23
Wrox Instant JavaScript – page - 25
Whitespace (Definition)
Whitespace is used to separate tokens from one another
Whitespace is used to improve the readability of the script and to separate tokens from one anotherwhere they could be misinterpreted if they were concatenated together
Whitespace characters are insignificant to the script execution apart from how they may affect theinterpretation of tokens The placement of whitespace can affect the way an expression is
evaluated For example:
Trang 34The following characters are considered to be whitespace in ECMAScript conforming JavaScriptinterpreters:
- Other category "Zs" Other Unicode space characters <USP>ECMA edition 3 adds a couple of new whitespace character definitions One is the non-breakingspace and the other refers generally to Unicode spacing characters
Cross-references:
ECMA 262 edition 2 – section - 7.1
ECMA 262 edition 3 – section - 7.2
O'Reilly JavaScript Definitive Guide – page - 28
window (Property)
The window object also known as window.window
JScript - 1.0Internet Explorer - 3.02Netscape - 2.0
Trang 35Window adornments (Definition)
Another name for the furniture that surrounds a window
Refer to:
Window furniture
Window events (Definition)
Some events within the event-handling complex relate to windows and their behaviors
These events are generally triggered by clicking on a window adornment or executing a methodcall on a window that simulates the effect of clicking on a window border item
See also: onBack, onForward, onLoad, onMove, onResize, onScroll, onUnload
Window feature list (Definition)
The list of available features that a window.open() method can apply
The feature list defines how the new window that is to be created will appear For example, youcan control the appearance of the various window adornments
The features are generally presented as a name-value pair, thus:
name=value
The features are either available for use as simple switches and will control the functionalitydepending on whether they are present or not Some also support an optional value while othersrequire a mandatory value Features requiring a mandatory value are generally numeric in nature.The switching values may be "yes" or "1" to enable a feature and "no" or "0" to disable a feature.Switching features can be used with no associated value This will generally default to "yes"
As you would expect, MSIE and Netscape Navigator support a completely different and
incompatible set of features Even controlling the same attribute of the window may requiredifferent feature names to be used (for example width in MSIE and innerWidth/outerWidth inNetscape Navigator)
The feature names are case insensitive but good style dictates that they are specified as shown inthe table
Trang 36Here is a summary of the available features of a window.open() method:
alwaysLowered - 4 No This dictates that a window should always be
at the bottom of the stack of windows
alwaysRaised - 4 No This dictates that a window should always be
at the top of the stack of windows
channelMode - No 4 Controls whether the window is presented in
channel mode
dependent Yes/No 4 No If a window is not dependent, it can survive
after its creator has been closed
directories Yes/No 4 No Controls the appearance of the Netscape
Navigator personal toolbar
fullscreen - No 4 On the Windows platform, MSIE will fill the
screen with the window
height Number 2 4 This will set the window to the height value.hotkeys Yes/No 4 No Setting this value to "no" will disable most
keyboard shortcuts apart from the quit option.innerHeight Number 4 No This will set the window to the height value
measured inside the window border
innerWidth Number 4 No This will set the window to the width value
measured inside the window border
left Number 4 4 The left edge of the window will be positioned
N pixels from the left edge of the screen.location Yes/No 2 4 The location bar is visible
menubar Yes/No 2 No The menubar is fully populated with menus
and menu items
outerHeight Number 4 No This will set the window to the height value
measured outside the window border
outerWidth Number 4 No This will set the window to the width value
measured outside the window border
resizable Yes/No 2 4 The window displays resize facilities according
to the switch value
screenX Number 4 No An alternative name for the left feature.screenY Number 4 No An alternative name for the top feature.scrollbars Yes/No 2 4 Scroll bars are explicitly displayed according to
the switch value
status Yes/No 2 4 The window displays a status bar according to
the switch value
toolbar Yes/No 2 4 The window displays a toolbar according to the
switch value
pixels from the top edge of the screen
width Number 2 4 This will set the window to the width value
at the same z-position in the stack of windows
Trang 37The following z-order feature switch values require the UniversalBrowserWrite privilege to beenabled when they are used in Netscape Navigator:
❑ For those features that require UniversalBrowserWrite privilege in Netscape Navigator, thetime at which you request the feature may affect how the window is presented This may be
platform specific and Netscape Navigator may behave differently according to the UI rules andappearance of the hosting platform
❑ In Netscape Navigator, on the Macintosh platform, setting the alwaysLowered feature willplace a window at the bottom of the Z stacking order That window will be permanently
inactive as long as another window is open It will be styled as a normal window If the
alwaysRaised feature is applied, the window will be placed on top and will be permanentlyactive In addition, the style is changed to that of a floating dialog (a Windoid in Macintosh UIparlance) A floating dialog in the Macintosh has a slimmer window border and a window titlebar that is not as thick as a normal window
❑ The fullscreen mode in the MSIE browser is not supported on the Macintosh platform
❑ If you specify dimensions for the window, you must specify both the horizontal and verticalvalues otherwise Netscape Navigator will ignore the setting MSIE will happily take only one ofthe values and provide a default for the other Netscape Navigator requires both height andwidth but doesn't care what sort You can mix innerHeight and outerWidth or height andinnerWidth for example
❑ Note that if the top or left values are specified on their own, the missing value will default to zero
in both MSIE and Netscape Navigator
❑ The scrollbars feature forces scroll bars to be present or not according its value in both browsers.However, scroll bars appear automatically if needed on MSIE even if the scrollbars feature isomitted On Netscape Navigator, they will only be available if you explicitly ask for them
Trang 38Window furniture (Definition)
The various controls and scrollbars on a window border Sometimes called window
adornments or chrome
The window furniture includes the following items:
❑ The location bar
❑ The active menu bar while the window is front-most
❑ The personal items bar
❑ Horizontal and vertical scrollbars
❑ The status bar at the bottom of the window
❑ The toolbar at the top of the window
These can all be controlled from scripts in Netscape Navigator A script is always allowed tomodify its own window with a call like this:
open("", "_top", aFeatureList)
It may require privileges to be enabled if it is going to alter another window (depending on thesource of each window's documents) They can also be controlled in MSIE but only when a window
is created with the window.open() method
Window.personalbar, Window.scrollbars, Window.statusbar,Window.toolbar
Window object (Object/browser)
An object representing a window or frame This object exposes methods, properties, and eventsassociated with it to the script
JScript - 1.0Internet Explorer - 3.02Netscape - 2.0
Trang 39anIndex An index to a window object
Argument list:
aFrameName The name of a frame in the window
Object properties: clientInformation, clipboardData, closed, crypto,defaultStatus, dialogArguments, dialogHeight,
dialogLeft, dialogTop, dialogWidth, document, event,external, frame, frameRate, history, innerHeight,innerWidth, java, length, location, locationbar, Math,menubar, name, navigator, netscape, offScreenBuffering,opener, outerHeight, outerWidth, Packages, pageXOffset,pageYOffset, parent, personalbar, pkcs11, returnValue,screen, screenLeft, screenTop, screenX, screenY,scrollbars, secure, self, sidebar, status, statusbar,sun, toolbar, top, window
Object methods: alert(), attachEvent(), back(), blur(),clearInterval(), clearTimeout(), close(), confirm(),
detachEvent(), disableExternalCapture(),enableExternalCapture(), execScript(), find(), focus(),forward(), home(), moveBy(), moveTo(), navigate(),open(), print(), prompt(), resizeBy(), resizeTo(),scroll(), scrollBy(), scrollTo(), setHotkeys(),setInterval(), setResizable(), setTimeout(),setZOptions(), showHelp(), showModalDialog(),showModelessDialog(), stop()
Functions: atob(), btoa(), captureEvents(), handleEvent(),releaseEvents(), routeEvent()
onDragDrop, onError, onFocus, onHelp, onLoad,onMouseMove, onMove, onResize, onScroll, onUnload
Since the on-screen window persists as long as the window is open, you might think it may be auseful place to store some session state data between documents Clearly, storing session data in adocument object is no use if the document is going to be discarded and replaced However,
anything created by a script belonging to a window is going to get zapped when the documentgoes away, so you cannot store persistent values in the window object like that because the globalobject for a web page is recreated each time a page is loaded
Storing session state data is best accomplished with a frame-set and some accessor scripts that arecalled within it
Event handling support via properties containing function objects was added to window objects inversion 1.1 of JavaScript
Trang 40❑ Be aware that if you store a reference to a window object and the window is closed, if you don'tdispose of the reference to the window object then it cannot be garbage collected A window objectwith no associated window is not much use unless you need to keep the object persistent due tohaving added some properties to it If this is the case, then, arguably, the window object was thewrong place to put such things
See also: BODY object, captureEvents(), Collection object, Document object,
Document.activeElement, Document.captureEvents(),Document.frames[], Document.parentWindow,
Document.releaseEvents(), EventCapturer object, Frame object,Frames object, Global object, IFRAME object, Layer.captureEvents(),Layer.releaseEvents(), Layer.window, self, Window.frame
client
ReadOnly,DontEnum
Table continued on following page