macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Scripting for IE 5 Macintosh Edition
Pages: 1, 2, 3

document.all in Nav 6

You can simulate the document.all collection in Netscape 6 in a variety of ways. For a page whose element structure does not change under script control, you can instruct NN6 to create a document.all property through W3C DOM syntax. The following function, which should execute immediately after the page loads, shows a compact implementation:



function initAll() {
  document.all = (document.all) ? document.all : 
    ((document.getElementsByTagName("*").length > 0) ?
    document.getElementsByTagName("*") : null)
}
...
<BODY onLoad="initAll()">

After this function runs, any IE4 or W3C DOM browser provides access to an element object through the document.all.elementID syntax.

The IE5/Mac DOM Implementation

Many are surprised to hear that separate Microsoft teams produce Macintosh and Windows versions of Internet Explorer. This is quite different from, for example, the way Netscape Navigator 6 shares the same core browser engine in all operating systems. One result of Microsoft's approach is that the two browsers are not always on the same release schedule and therefore do not necessarily contain the same DOM features. Moreover, if you compare the resulting DOM implementations in IE5 for Windows and Macintosh, you might conclude that the Mac development team exercises its own discretion when it comes to implementing DOM specifics. The Windows version of the DOM may contain both Microsoft proprietary and W3C DOM syntax for a particular property or method of an HTML element object. In contrast, the Macintosh version may omit the Microsoft proprietary syntax in favor of the W3C DOM version. Overall, IE 5.0 for Macintosh provides more direct support for W3C DOM syntax than even the later IE5.5 for Windows does.

Lest you throw your hands up in the air in despair, take comfort in knowing that you can still count on a lot of basic DOM functionality and syntax implemented in versions of IE for Mac and Windows. For example, in addition to support for the document.all collection, both platforms support the popular set of element object properties that facilitate direct manipulation of page content:innerHTML, innerText, outerHTML, and outerText.

Scripts in both browsers can control style sheet properties by way of an element object's style property. The fundamental IE4 event model is also consistent across both platforms.

In the Version 5 implementations of IE, both the Macintosh and Windows versions support enough of the W3C DOM node object model to be functional. Since the W3C DOM provides syntactically identical access to style sheet properties as the IE4 DOM does, you don't have to learn any new tricks to be compatible in that department. Perhaps the largest omission in the IE5 family is the W3C DOM event listener model, but IE5 for both Mac and Windows continue to support the IE4 event model.

Viewing the compatibility scene from high overhead, it appears as though a lot of code written for IE/Windows would run smoothly under IE/Macintosh -- and it does. But if you let your script writing be governed by all of the syntax devised for the Windows version, you could find yourself in trouble when you get down to the details. It's time to see which Microsoft DOM items are out of bounds once you leave the Windows version.

Win32-Only Technologies

Internet Explorer for Windows bundles numerous ActiveX controls, some of which the browser requires for normal operation. The browser also has instant communication with other ActiveX controls on the client machine, whether the controls are part of the Windows operating system or are downloaded or installed from third parties. What most other browsers treat as "plug-ins" are implemented as ActiveX controls for IE/Windows. Although IE5/Macintosh offers a modicum of support for ActiveX, the controls devised for Windows do not run under other operating systems, nor have IE/Windows built-in controls (such as the basic Web Browser Control, on which many IE/Windows features are built) been implemented as such in IE/Mac.

As a result, a few powerful Windows-only features are not available on the Mac version. These include Data Binding (direct connectivity to server data sources via the Data Source Object), CSS filters (for transition visual effects and text effects), DHTML Behaviors (the action-oriented equivalent to external style sheet definitions), IE 5.5 content editing, executing external commands (via the execCommand()method), and the TextRange object (allowing script control of arbitrary blocks of text independent of their HTML containers).

Admittedly, this is a long list of features not built into IE/Mac. Most of them are also missing from Netscape Navigator 6 on all OS platforms because (with the exception of the similar, but incompatible TextRange object) these features are not part of the W3C DOM standards -- at least not yet. Therefore, if you want to deploy these features on a public Web site's pages, apply them as additive, rather than mission-critical, aspects of the page. For example, you can apply barndoor transitions between pages of your site, but only IE/Windows users will see the effect.

Fewer Event Types

Compared to Explorer 4, versions 5 and 5.5 for Windows nearly double the number of event types that HTML element objects recognize. For instance, several event types in IE5 signal user dragging motions with respect to an element (onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop). Another event group provides script control over cutting, copying, and pasting content (onBeforeCopy, onBeforeCut, onBeforePaste, onCopy, onCut, onPaste). And still another event type (onContextMenu) makes it easy to interrupt the system-produced context (right-click on the Windows mouse) menu and create custom menus.

In contrast, the IE/Macintosh event repertoire stays within the W3C DOM. Thus, you have the range of mouse, keyboard, and system-generated events that you have come to know and love in IE4 and NN4.

Speaking of events, the IE/Macintosh eventobject is a property of the windowobject, just as it is in IE/Windows. In IE5/Mac, however, the eventobject's properties include not only the IE4 properties, but also some W3C DOM eventobject properties, such as event.charCode(character and key codes are not necessarily the same values) and event.target(the W3C DOM equivalent of event.srcElement).

Pages: 1, 2, 3

Next Pagearrow