问题
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.
回答1:
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.
回答2:
To embed objects, I'd recommend using a library like swfobject, because yes, IE is definitively doing something funky with this tag.
回答3:
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.
来源:https://stackoverflow.com/questions/981856/does-internet-explorer-remove-the-object-element-from-dom