Internet Explorer 4 Resource Kit Chapter 26 - Active Scripting

In This Chapter

Active Scripting Overview

ECMAScript: The Internet Standard

JScript 3.0 in Internet Explorer 4

JScript 3.0 Availability Differences between JScript 3.0 and JavaScript 1.2

Top of pageTop of page

Active Scripting Overview

With the increasing popularity of Web applications, many Web developers are augmenting their HTML authoring skills by learning a scripting language. With the next generation of Web browsers, however, developers need to decide which scripting language to learn and which scripting features to take advantage of. Before making this decision, it is important to understand which scripting languages are supported by each browser and each browser's corresponding level of compliance with standards.

Internet Explorer 4 supports both JScript and Visual Basic Scripting Edition (VBScript). The modular script architecture of Internet Explorer is designed so that any third party can add scripting-language support to Internet Explorer using the Active Scripting interface. This enables developers to use the languages they know today to create Web pages and ensures that they have the most up-to-date and complete scripting language support available. For more information, see "ActiveX Scripting" in the Microsoft Internet Client SDK.

In addition, Microsoft is working with other industry leaders to ensure a broad level of scripting interoperability among third-party products. Consistent with this effort, Internet Explorer includes the JScript 3.0 scripting engine, the industry's first implementation of the new ECMA-262 specification.

For information about troubleshooting authoring for Internet Explorer and for Frequently Asked Questions (FAQs) about scripting, see Appendix G and I, respectively.

Top of pageTop of page

ECMAScript: The Internet Standard

The need for a scripting standard is clear. A scripting standard ensures that Web developers understand the direction of the industry and that they can write code consistent with this direction. It also allows developers to author script that will run seamlessly across a variety of products.

The European Computer Manufacturers Association (ECMA) scripting language committee was formed last year with the charter to standardize "the syntax and semantics of a general-purpose, cross-platform, vendor-neutral scripting language." Along with companies such as Borland, IBM, Netscape, and Sun Microsystems, Microsoft has participated actively in the development of the ECMAScript standard. A joint specification from Borland, Microsoft, and Netscape was recently ratified by the committee and published as the ECMA-262 specification.

With products such as Internet Explorer 4 and Internet Information Server 4.0, Microsoft is delivering JScript 3.0, the first scripting language to conform fully to ECMA-262. Microsoft is continuing to work with the ECMA scripting committee to ensure the advancement of the ECMA Internet Scripting Standard.

Basically, the ECMA-262 specification describes a Web scripting language that can enrich and enliven Web pages in a Web browser. More specifically, the ECMA-262 specification outlines an object-oriented programming language for performing computations and manipulating objects within a host environment, such as the browser. The complete ECMA-262 specification can be found at http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM .

From a client perspective, a Web browser provides an ECMAScript host environment for client-side computations. These computations can include objects that represent windows, menus, pop-up menus, dialog boxes, text areas, anchors, frames, history, cookies, and input/output. In addition, the Web browser provides a means to attach scripting code to events such as change of focus, form submission, mouse actions, page and image loading, and others. The scripting code appears in-line with the HTML, and the rendered page is a combination of HTML elements and scripting engine computations.

Top of pageTop of page

JScript 3.0 in Internet Explorer 4

Microsoft JScript 3.0 is the first completely compliant industry implementation of the ECMA-262 specification. For more information about the feature/keyword syntax, visit the JScript Web site at http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28001169 .

Microsoft has also submitted additional language functionality to the ECMA scripting committee for the next version of the ECMA specification. These features are being delivered in JScript 3.0, to provide the most advanced functionality for Web scripting available.

The following table describes the scripting features available in the ECMA-262 specification and Internet Explorer 4.

CategoryFeature/Keyword

Array Handling

Array object, join method, length property, reverse method, sort method

Assignments

Assign (=) operator, Addition (+=) operator, Bitwise AND (&=) operator, Bitwise OR (|=) operator, Bitwise XOR (^=) operator, Division (/=) operator, Left Shift (<<=) operator, Modulus (%=) operator, Multiplication (*=) operator, Right Shift (>>=) operator, Subtraction (-=) operator, Unsigned Right Shift (>>>=) operator

Booleans

Boolean object

Comments

/* .. */ or // statements

Constants/Literals

NaN property, null, true, false, Infinity property, undefined

Control Flow

break statement, continue statement, for statement, for…in statement, if…else statement, return statement, while statement

Dates and Time

Date object, getDate method, getDay method, getFullYear method, getHours method, getMilliseconds method, getMinutes method, getMonth method, getSeconds method, getTime method, getTimezoneOffset method, getYear method, getUTCDate method, getUTCDay method, getUTCFullYear method, getUTCHours method, getUTCMilliseconds method, getUTCMinutes method, getUTCMonth method, getUTCSeconds method, setDate method, setFullYear method, setHours method, setMilliseconds method, setMinutes method, setMonth method, setSeconds method, setTime method, setYear method, setUTCDate method, setUTCFullYear method, setUTCHours method, setUTCMilliseconds method, setUTCMinutes method, setUTCMonth method, setUTCSeconds method, toGMTStrong method, toLocaleString method, toUTCString method, parse method, UTC method

Declarations

function statement, new operator, this statement, var statement, with statement

Function Creation

Function object, arguments property, length property

Global Methods

Global object, escape method, unescape method, eval method, isFinite method, isNaN method, parseInt method, parseFloat method

Math

Math object, abs method, acos method, asin method, atan method, atan2 method, ceil method, cos method, exp method, floor method, log method, max method, min method, pow method, random method, round method, sin method, sqrt method, tan method, E property, LN2 property, LN10 property, LOG2E property, LOG10E property, PI property, SQRT1_2 property, SQRT2 property

Numbers

Number object, MAX_VALUE property, MIN_VALUE property, NaN property, NEGATIVE_INFINITY property, POSITIVE_INFINITY property

Object Creation

Object object, new operator, constructor property, prototype property, toString method, valueOf method

Operators

Addition (+) operator, Subtraction (-) operator, Modulus arithmetic (%) operator, Multiplication (*) operator, Division (/) operator, Negation (-) operator, Equality (==) operator, Inequality (!=) operator, Less than (<) operator, Less than or Equal to (<=) operator, Greater than (>) operator, Greater than or Equal to (>=) operator, Logical And (&&) operator, Or (||) operator, Not (!) operator, Bitwise And (&) operator, Bitwise Or (|) operator, Bitwise Not (~) operator, Bitwise Xor (^) operator, Bitwise Left Shift (<<) operator, Bitwise Right Shift (>>) operator, Unsigned Right Shift (>>>) operator, Conditional (?:) operator, Comma (,) operator, delete operator, typeof operator, void operator, Decrement (--) operator, Increment (++) operator

Objects

Array object, Boolean object, Date object, Function object, Global object, Math object, Number object, Object object, String object

Strings

String object, charAt method, charCodeAt method, fromCharCode method, indexOf method, lastIndexOf method, split method, toLowerCase method, toUpperCase method, length property

The following table describes those additional JScript 3.0 features submitted by Microsoft to ECMA but not included in the ECMA-262 specification.

CategoryFeature/Keyword

Array Handling

concat method, slice method, VBArray object, dimensions method, getItem method, lbound method, toArray method, ubound method

Conditional Compilation

@cc_on statement, @if statement, @set statement, @_win32 variable, @_win16 variable, @_mac variable, @_alpha variable, @_x86 variable, @_mc680x0 variable, @_PowerPC variable, @_jscript variable, @_jscript_build variable, @_jscript_version variable

Control Flow

do…while statement, Labeled statement, switch statement

Dates and Time

GetVarDate method

Enumeration

Enumerator object, atEnd method, item method, moveFirst method, moveNext method

Function Creation

Caller property

Operators

Identity (===) operator, Nonidentity (!==) operator

Objects

Enumerator object, RegExp object, Regular Expression object, VBArray object

Regular Expressions and Pattern Matching

RegExp object, index property, input ($_) property, lastIndex property, lastMatch ($&) property, lastParen ($+) property, leftContext ($') property, multiline ($*) property, rightContext ($') property, $1…$9 property, global property, ignoreCase property, lastIndex property, source property, compile method, exec method, test method, Regular Expression Syntax

Strings

concat method, slice method, match method, replace method, search method, anchor method, big method, blink method, bold method, fixed method, fontcolor method, fontsize method, italics method, link method, small method, strike method, sub method, sup method

JScript 3.0 Availability

JScript 3.0 can be downloaded from the JScript Web site at http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28001169 . JScript 3.0 will ship with the following Microsoft products:

Microsoft Internet Explorer 4 

Microsoft Internet Information Server 4.0 

Microsoft Windows Script Host 

Software developers can license JScript or Visual Basic Scripting Edition from Microsoft to use as the scripting language in their own applications. JScript and VBScript are available from Microsoft in two forms: as a ready-to-run (compiled) binary for several platforms or as source code. Licensing details can also be found at http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28001169 .

Differences between JScript 3.0 and JavaScript 1.2

If you're designing Web pages that may be used by more than one type of browser, and you're using advanced technologies such as JScript and JavaScript, it's important to understand potential compatibility issues that may arise. For example, Netscape's JavaScript 1.1 served as the original basis for ECMA-262, although Netscape has yet to implement the ECMA-262 specification. In the latest releases of Netscape's Navigator software, JavaScript 1.2 does not comply with the ECMA-262 specification, and code written to JavaScript 1.2 works only with the version 1.2 scripting engine in Navigator.

As a result of Microsoft's standards support, code written using JScript 3.0 will work with other industry implementations of the ECMA-262 specification, including a future implementation from Netscape. In addition, Microsoft will ship the same JScript implementation in all versions of Internet Explorer 4, so developers can count on the same scripting behavior, regardless of the browser platform.

The following table details the support for the ECMA-162 Internet scripting standard offered by Microsoft Internet Explorer 4 and Netscape Navigator 4.0 and describes the corresponding behaviors in each browser. Developers can use this table as a tool to help during the migration process if scripting errors or anomalies arise with pages on your intranet.

Standard Feature or Behavior categoryMicrosoft Internet Explorer 4Netscape Navigator 4.0

\u1234 used to specify unicode character

Fully supported

Not supported

Hexadecimal constants longer than 8 digits

Fully supported

Not supported

Octal constants that overflow 32 bits

Fully supported

Not supported

Negative Zero

Fully supported

Not supported

Date object

Fully supported

7th parameter (ms) not supported

Date.toUTCString

Fully supported

Not supported

Date.getFullYear

Fully supported

Not supported

Date.setFullYear

Fully supported

Not supported

Date.getUTCFullYear

Fully supported

Not supported

Date.setUTCFullYear

Fully supported

Not supported

Date.getUTCMonth

Fully supported

Not supported

Date.setUTCMonth

Fully supported

Not supported

Date.getUTCDate

Fully supported

Not supported

Date.setUTCDate

Fully supported

Not supported

Date.getUTCDay

Fully supported

Not supported

Date.setUTCDay

Fully supported

Not supported

Date.getUTCHours

Fully supported

Not supported

Date.setUTCHours

Fully supported

Not supported

Date.getUTCMinutes

Fully supported

Not supported

Date.setUTCMinutes

Fully supported

Not supported

Date.getUTCSeconds

Fully supported

Not supported

Date.setUTCSeconds

Fully supported

Not supported

Date.getMilliseconds

Fully supported

Not supported

Date.setMilliseconds

Fully supported

Not supported

Date.getUTCMilliseconds

Fully supported

Not supported

Date.setUTCMilliseconds

Fully supported

Not supported

NaN Dates

Fully supported

Not supported, set time to 0 (Jan 1, 1970 UTC) instead

Full range of –100,000,000 days before Jan 1, 1970 UTC to 100,000,000 days after Jan 1, 1970 UTC

Fully supported

Not supported

Eval method

Fully supported

Supported, but often returns an incorrect value

== operator

Fully supported

Supported, but doesn't match standard specification

+ operator

Fully supported

Supported, but often returns incorrect results

Number formatting

ECMA standard behavior

Supported, but often returns incorrect results

Calling through a local function should pass the sglobal object as the "this" value

ECMA standard behavior

Passes activation object instead

Bind once to left operand on side-effect operators

ECMA standard behavior

Binds twice

Delete operator

ECMA standard behavior

Returns undefined

New operator

ECMA standard behavior

Grammar parsed incorrectly

Math.atan2 method

ECMA standard behavior

Does not implement many of the special cases listed in the standard specification


Top of pageTop of page