This topic has not yet been rated - Rate this topic

OBJECT Fallback Is Included in DOM and Matched by window[name]

Affected Internet Explorer Document Mode

Internet Explorer 9 Standards

Feature Impact

Severity: High
Probability of Impact: Medium

Description

When an OBJECT element has fallback content (typically, an EMBED element), Windows Internet Explorer 9 now parses this content and includes it in the Document Object Model (DOM), whereas previous versions of Internet Explorer did not. This behavior change makes Internet Explorer 9’s handling of such elements more standards-compliant and interoperable.

As a result, if an OBJECT element has the same name attribute as any of its fallback elements, then window[“myName”] will now return a collection of all elements with the name “myName”. Pages that assume Internet Explorer will return a single element (typically, the OBJECT element) as opposed to a collection can cause an exception to occur when accessing methods and properties on the returned value.

Affected Areas

If you use the same name attribute for an OBJECT element as you do for the fallback content and attempt to retrieve a reference to the instantiated plugin using window[name], more than one element will be returned, where only the OBJECT element was returned in previous versions of Internet Explorer.

For example, consider the following script and markup:

Markup

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="myPlugin" 
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
     <param name="movie" value="myflash.swf" />
     <embed src="myflash.swf" name="myPlugin" type="application/x-shockwave-flash"
     pluginspage="http://www.adobe.com/go/getflashplayer"></embed>
</object>

JavaScript

plugin = window["myPlugin"]; //the OBJECT element in IE8, a collection of the OBJECT and 
EMBED elements in IE9
plugin.style.display = "none";  //Causes an exception in IE9: “SCRIPT5007: Unable to set 
value of the property ‘display’: object is null or undefined”

 

In Internet Explorer 8, window[name] would return just the OBJECT element (because Internet Explorer8 did not include the fallback content in the DOM).

In Internet Explorer 9, the EMBED element is included in the DOM and thus window[name] returns a collection of both the OBJECT and EMBED elements. This behavior is interoperable with other browsers and is standards compliant.

Guidelines

When expecting the instantiated plugin, use document[name] instead of window[name]. document[name] will not match fallback elements when the parent is instantiated.


plugin = document["myPlugin"]; //the instantiated plugin: OBJECT element in IE, 
EMBED element in browsers which use the Netscape plugin model

Additional Details:

In Internet Explorer 9 Beta, document[“myPlugin”] returned the EMBED element and window[“myPlugin”] returned a HTML Collection of both the OBJECT and the EMBED elements in the above example.

However, the following common coding pattern was observed on numerous sites:


if(document[“myPlugin”]) {
     plugin = document[“myPlugin”]; //expected to be the object element in Internet Explorer and embed element in other browsers
}

To help site compatibility, Internet Explorer 9 Release Candidate has an improved behavior for document[name]. Provided the plugin loads successfully, it will return the instantiated plugin (in the above example, the OBJECT element). This effectively matches what Internet Explorer 8 returned while still allowing for standards-compliant parsing of the fallback content. This behavior allows for the above coding pattern to be interoperable in all major browsers.

window[name] remains unchanged from Internet Explorer 9 Beta and should only be used when expecting to match more than just instantiated elements. The following table describes how these APIs work in Internet Explorer 9.

window["foo"] returnsdocument["foo"] returns
  • a, applet, area, embed, form, frame, frameset, iframe, img, or object elements that have a name "foo", or
  • HTML elements that have an id "foo
  • embed or object elements that are showing and have a name or id of “foo”, or
  • embed or fallback-free object elements, which have no object ancestor that is showing, and have a name or id of “foo”, or
  • object elements that are either showing or have no ancestor that is showing, and have an id of “foo”, or
  • applet, form, iframe or img elements that have a name “foo”, or
  • applet elements that have an id “foo”, or
  • img elements that have an id “foo”, and that also have a name content attribute present

 

An object element is said to be fallback-free if it has no object or embed descendants.

Related Topics

 

 

Send comments about this topic to Microsoft

Build date: 6/11/2011

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Adobe Systems Incorporation
Technical Support