0

I have markup in my page that includes the tag:

<body>
  <object codebase="blah" codetype="text/blah">
    <param name="name" value="value"/>
    <div>Some Markup</div>
  </object>
</body>

The idea is for browsers to display the content of the <div> by default, but if a special JS library is present, it will find all the elements and transform the ones it cares about (based on @codetype).

This works in Firefox and WebKit, but fails in IE, because that browser seems to strip off the outer <object> element, and just leaves the inner <div>. That is, under Explorer, the DOM I get from the above markup looks like this:

<body>
  <div>Some Markup</div>
</body>

Is this a documented behavior? Is there any way to make IE preserve the <object> element in the DOM untouched? (I am currently testing this with IE7.)

Note: This isn't for embedding Flash, or similar multimedia.


To embed objects, I'd recommend using a library like swfobject, because yes, IE is definitively doing something funky with this tag.

4

3 回答 3

2

Hmm... According to a post on MSDN, Internet Explorer before version 7 would remove from DOM any <object> whose content couldn't be rendered.

I guess this makes my problem a catch-22. I can add some data that would make IE render the <object> (such as make it show a 1 pixel image), which would enable the Element in the DOM, but this would hide the "fallback" markup.

于 2009-06-11T16:07:19.480 回答
0

If you try to create an object, and it cannot be instantiated, it wouldn't surprise me if the object tag didn't end up being part of the DOM.

于 2009-06-11T15:45:20.220 回答
0

要嵌入对象,我建议使用像swfobject这样的库,因为是的,IE 肯定会用这个标签做一些时髦的事情。

于 2009-06-11T15:38:10.067 回答