This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
|
Microsoft Internet Explorer 5.0: The Inside Story
by the Microsoft Internet Explorer SDK Documentation Team Stephen Cote Jeff Kirkham Erik Kjerland Lanie Kurata Jacqueline Sowell Bradley Yamauchi |
Internet Explorer 5.0 expands the horizons of the Internet. The new version boasts improvements in extensibility and has become a rich platform for application design. |
After years of improvement, the technology of the extensible browser comes of age with Microsoft® Internet Explorer 5.0. This browser release has been driven by three strategic objectives: it needed to be fast and stable, it had to be easily extensible, and the browser itself was to become a rich platform for applications. Well focus on the latter two goals. We will preview some of the new features in Internet Explorer 5.0 that make it an extensible environment for application developers, including Dynamic HTML (DHTML) behaviors, user data persistence, dynamic properties, data transfer, and mouse capture. (Note that this article is based on the Developer Preview release, and features are subject to change in the final version.)
DHTML Behaviors
|
Mouseover highlights and controlling when content is shown or hidden are two popular effects made possible in Internet Explorer 4.0. Figure 1 shows how these two effects have been applied to MSDN table of contents. To illustrate some differences between Internet Explorer 4.0 and 5.0, we implemented the same page two different ways. The code in Figure 2 uses DHTML features of Internet Explorer 4.0. It requires a combination of HTML and lots of script on the page. The code in Figure 3 uses DHTML behaviors with Internet Explorer 5.0. Notice that most of the script is confined to a separate file.
Behaviors makes the page much more readable, and thus more maintainable. It is also easy to use the same behavior on different elements on a page, and even across multiple pages.
Two behaviors were created for this example: one (hilite.sct) to implement the mouseover highlighting effect, and the other (showHide.sct) to show or hide text by expanding and collapsing the list when clicked. These behaviors are applied to the <A> and <LI> elements on the page in the same way a style is applied to an element through Cascading Style Sheets (CSS). The proposed CSS behavior attribute specifies the location of the behavior you want to apply to the element.
This code defines two embedded styles, COLLAPSING and A.
<HEAD>
<STYLE>
A {behavior:url(hilite.sct)}
.COLLAPSING {behavior:url(showHide.sct)}
</STYLE>
</HEAD>
The first style uses the HTML element <A> as the selector, causing each instance of an <A> tag on the page to change its color to red when the mouse moves over it. This behavior is defined in the file hilite.sct. The second style defines a COLLAPSING class and uses it as a selector. Every element with CLASS="COLLAPSING" behaves as defined in showHide.sct, toggling its display property.
<UL>
<LI><DIV CLASS="COLLAPSING" CHILD=Topics1>HTML
Authoring</DIV>
<UL ID=Topics1>
<LI><A HREF="">Internet Explorer 4.0 authoring
tips</A>
<LI><A HREF="">Four special effects with IE
4.0</A>
...
</UL>
</UL>
If youve ever designed a form, chances are youve had a need for a masked entry fieldan input field that takes a preformatted value like a phone number, a date, or a time. The <INPUT> tag does not have this functionality built in; with Internet Explorer 4.0 you have to use a script that monitors the keypress and focus events, then set the input value to the formatted string accordingly. Consequently, you have to include the same script on every page that uses those masked entry fields.
<HEAD>
<STYLE>
.MASK {behavior:url(mask.sct)}
</STYLE>
</HEAD>
<input type=text class="mask" mask_Value="(###) ###-####">
In the style definition, mask.sct is the name of the file that contains the behavior implementation. The <INPUT> parameter mask_Value defines the formatting required for the input fieldin this case, a phone number. You should find this simple to use, even if you barely know how to write a script! Figure 4 shows this sample in action.
Implementing Behaviors
<STYLE>
.COLLAPSING { behavior:url(#myObject) }
</STYLE>
<OBJECT ID=myObject ... ></OBJECT>
<UL>
<LI CLASS="COLLAPSING">HTML Authoring
<UL>
<LI>IE 4.0 authoring tips
:
</UL>
</UL>
Creating behaviors in C++ is beyond the scope of this article. The C++ interfaces involved are documented for the Developer Preview release of Internet Explorer 5.0. See http://msdn.microsoft.com/workshop/c-frame.htm#/workshop/browser/default.asp for more information.
Behaviors and Data Persistence
Several of the DHTML behaviors included with Internet Explorer 5.0 allow you to instruct the browser to preserve Web page information. Form data, styles, state, and script variables can be persisted in the current sessions memory stream, in the favorites list, in HTML, or in XML. These four DHTML persistence behaviors are saveFavorite, saveHistory, saveSnapshot, and userData.
function fnSaveInput()
{
var oPersist = oPersistForm.oPersistText;
oPersist.setAttribute("sPersistText",oPersist.value);
oPersist.save("oXMLBranch");
oPersist.value = "";
}
After the fnSaveInput function calls the save method, the form input value is cleared.
function fnLoadInput()
{
var oPersist = oPersistForm.oPersistText;
oPersist.load("oXMLBranch");
oPersist.value = oPersist.getAttribute("sPersistText");
oPersist.removeAttribute("sPersistText");
oPersist.save("oXMLBranch");
}
The persistent input field and the two buttons that call the save and load functions are mostly plain HTML (see Figure 8). A class attribute identifies the input field as participating in userData persistence, and an onclick event handler on each button fires the save and load functions.
function fnSaveInput()
{
var oPersist = oPersistForm.oPersistText;
var oXMLDoc = oPersist.XMLDocument;
var oNode = oXMLDoc.createNode(0,"Trunk");
oNode.nodeValue = "The XML tree trunk.";
oNode.setAttribute("sPersist",oPersist.value);
oXMLDoc.documentNode.insertNode(oNode);
oPersist.value = "";
oPersist.save("oXMLBranch");
}
To add information in an attribute on an XML node, the oXMLDoc variable is assigned to the persistent objects XMLDocument property. The oNode object is then created from the oXMLDoc variable using createNode, an XML method. An arbitrary name (Trunk) and value ("The XML tree trunk") is given to the oNode object. The information from the input value is stored in an attribute on the oNode object, and the node is inserted into the XML documentNode. When the persistent information is saved to the XML store, the data resides in an XML structure.
function fnLoadInput()
{
var oPersist = oPersistForm.oPersistText;
var oXMLDoc = oPersist.XMLDocument;
oPersist.load("oXMLBranch");
oPersist.value =
oXMLDoc.documentNode.childNodes.item(0).getAttribute("sPersist");
}
Beyond the adjustments to the two JScript-based functions, the HTML from Figure 8 remains the same after XML-osity is added.
Dynamic Properties
Dynamic properties let you improve the appearance and rendering of Web pages. Using dynamic properties, it is possible to declare HTML property values as an expression or formula. The expressions used in a dynamic property can reference property values from other elements, allowing greater interactivity between objects on a page.
Here are a few of the effects you can create with dynamic properties:
div1.style.setExpression("posLeft","div2.style.posLeft +
div2.clientwidth","jscript");
The setExpression method sets a dynamic property in script. The first parameter is the name of the property to be recalculated. The second is the scripting equation to be applied to the property. The third is the scripting language to use for the equation. Note how the setExpression method is called directly on the object that has the property. In the above code, the target property posLeft is a property of that style object (not div1 itself), so setExpression is called on the style object.
<DIV ID=div1 STYLE="left:function(div2.style.posLeft + div2.clientWidth)">
One of the benefits of using the function notation versus the setExpression method is that it degrades to other browsers much more gracefullythey simply ignore it. With setExpression, you must write conditional code, sniffing the browser string to make sure that you dont call a method that will return an error. By using inline dynamic properties, script usage can be minimized. This lets page designers create advanced effects without having to learn script programming.
![]() |
Figure 10: DIV Before Browser is Resized |
For the Internet Explorer 5.0 Developer Preview release, implicit dependencies, internal property changes, and related properties may result in some expressions not being recalculated even though the properties they reference may have changed. To guard against these issues, refer to the same property name or manually call recalc(true) to force recalculations of all expressions. The code shown in Figure 9, for example, calls the recalc method on the onload and onresize events, which forces a recalculation of the dynamic properties in the document.
Data Transfer
If you want to incorporate custom drag and drop or editing functionality in your Web apps, Internet Explorer 5.0 makes doing so straightforward with an extensive data transfer implementation. An important part of the data transfer object model is the new dataTransfer object and its supporting cast of properties and methods. The dataTransfer object is available as a property of the window event object, so it can be called like this:
event.dataTransfer.setData("Image")
It acts as the conduit for transferring information between the data source and the data target. The data source can provide both data and a data format in the same way that the target object can request data of a specified format. The setData and getData methods of the dataTransfer object are central to these exchanges of information.
function fnSetInfo()
{
event.dataTransfer.setData("Text", "Microsoft Golf");
event.dataTransfer.effectAllowed = "copy";
}
The setData method associates text with the source object, an image of the Microsoft Golf package. When the image is dropped on a valid drop target, such as an order form, then the text describing the merchandise is displayed.
function fnBeforeCopy()
{
event.returnValue = false;
}
As the examples illustrate, all of the data transfer communication takes place during events. Internet Explorer 5.0 delivers a rich set of notification events, all of which bubble. This level of programmatic control is a big help to Web developers. You can modularize your code by trapping these events once they bubble up to the container level.
Mice and Scrollbars
Want to include dropdown menus in your Web apps without resorting to ActiveX controls? Internet Explorer 5.0 delivers new functionality that makes monitoring mouse activity easy. The releaseCapture and setCapture methods and the onlosecapture event allow you to designate one object to trap all mouse events for the document.
Web page navigation now goes beyond the onscroll event of Internet Explorer 4.0. You can query which component the mouse is hovering over using the componentFromPoint method. This method detects any element the mouse is overnot just scroll bars. The following code writes the pointer position to the browser status bar each time the onmouseover event fires.
function fnTrackScroll()
{
var sElem = "";
sElem = document.body.componentFromPoint(event.clientX, event.clientY);
window.status = "mousemove " + event.clientX + ", " +
event.clientY +
" The mouse pointer is hovering over:
" + sElem;
}
You can also move scroll bar components using the doScroll method. This method scrolls the element by the same increments available on the scroll bar, whether vertically or horizontally. The following code causes the scroll bar to scroll horizontally one full page to the right.
function fnScrollBehavior()
{
document.body.doScroll("scrollbarPageRight");
}
This functionality lets accessibility related hardware, such as screen readers, relay much more navigational information to users with special needs.
Client Capabilities
Internet Explorer 4.0 introduced a number of enhancements to the DHTML object model that provide information about the client, such as the screen resolution, color depth, platform, whether cookies or Java applets are enabled, and so on. This information, collectively known as client capabilities, lets you query which features of the browser are currently enabled. This way you can serve up the right content and have the pages appear exactly as nature intended.
For example, using the colorDepth property as in the following code, you can dynamically specify the images to be used on the page based on the number of colors supported by the client screen.
<IMG ID="myImage" WIDTH=200 HEIGHT=200>
<SCRIPT>
{
if (window.screen.colorDepth >= 8)
myImage.src = "256color.bmp";
else
myImage.src = "16color.bmp";
}
</SCRIPT>
If fewer than 256 colors (or 8 bits per pixel) are detected, a 16-color image is displayed; otherwise, a higher resolution image is displayed. As a result, the colors are more suited to the client screen, and the overall user experience is improved.
Table Enhancements
The CSS table-layout attribute has been added to Internet Explorer 5.0, resulting in a significant performance boost for table rendering. In a simple test, a 1000-row table without a fixed layout took 50 seconds to load on a Pentium 90 system. With a fixed layout, the same table took under one second to load.
You can create a fixed-layout table by using a new CSS attribute, table-layout. The default, table-layout:auto, forces Internet Explorer 5.0 to determine the size of the table. To calculate the table size, Internet Explorer must examine the contents of each table cell. However, if you set table-layout:fixed and specify a table width, Internet Explorer 5.0 does not have to check the contents of each cell as it is loaded.
A fixed table layout will work only if Internet Explorer 5.0 can determine the table width. There are three ways to do this: specify table width manually, set the cell width for each cell, or stipulate the width of the columns. If you specify the table width by adding the width attribute to the table tag, Internet Explorer 5.0 will give each column an equal width. The following HTML will render a table with two 50-pixel-wide columns:
<TABLE WIDTH=100 style="table-layout:fixed">
<TR><TD>This is cell 1</TD><TD>This is cell 2</TD>
</TR>
</TABLE>
You can also specify the width of each column using the COL tag or by specifying a width attribute in each cell of the first table row. The following code will render a table with one 50-pixel-wide column and one 100-pixel-wide column:
<TABLE WIDTH=150 style="table-layout:fixed">
<COL WIDTH=50><COL WIDTH=100>
<TR><TD>This is cell 1</TD><TD>This is cell 2</TD>
</TR>
</TABLE>
The fixed value of the table-layout attribute is only effective when loading large tables predefined in the HTML page. It has less impact when used in conjunction with data binding or the innerHTML property of a table container.
A new CSS attribute, border-collapse, allows a table to look more like a spreadsheet. This attribute allows cell borders to be shared, giving a cleaner appearance to the page. Figure 15 shows the difference between a traditional HTML table and a table utilizing the border-collapse attribute. Internet Explorer 5.0 also lets you use the display attribute to selectively show or hide table data.
Unicode and URL Cache Group Support
For C++ programmers, Internet Explorer 5.0 is scheduled to include Unicode and URL cache group support for the Win32-based Internet functions (more commonly known as WinInet). Many of the Win32-based Internet functions and structures now provide a Unicode wrapper for the ANSI implementation. This allows developers who work in a Unicode environment to use WinInet without converting strings being passed into these functions and structures `from Unicode to ANSI. For backward compatibility, ANSI versions of the WinInet functions and structures will continue to be supported.
URL cache groups let you create non-removable groups of resources in the Internet cache. Resources added to these groups will not be purged by the normal clean-up mechanism used by the Internet cache, so users can access this content offline with Internet Explorer and other WinInet-based applications that were designed to access the cache.
Conclusion
Though Internet Explorer looks similar to its predecessor, dont be fooled. Internet Explorer 5.0 is designed to deliver increased performance and stability through fixed-layout tables, an enhanced rendering engine, and improved CSS support. In addition, with the introduction of DHTML behaviors, it brings the benefits of encapsulation and extensibility to Web development. Finally, it provides a rich platform for applications through dynamic properties, client capabilities, persistence, mouse capture, and many other improved features.
From the September 1998 issue of Microsoft Interactive Developer.