W3C home > Mailing lists > Public > public-html@w3.org > April 2008

Re: Reinitializing OBJECT and EMBED - data and type changes

From: Michael A. Puls II <shadow2531@gmail.com>
Date: Wed, 23 Apr 2008 15:25:23 -0400
Message-ID: <6b9c91b20804231225x5d53188fq306cb62fcae7aed2@mail.gmail.com>
To: "Boris Zbarsky" <bzbarsky@mit.edu>
Cc: public-html@w3.org

On 4/23/08, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> Michael A. Puls II wrote:
>
> > I assume the paragraph means: "If data or type is added or removed (in
> > any way) or modified (in any way, even to the same exact value)
> >
>
>  I would hope that the "even to the same exact value" part is not actually
> the intent.

Because it might ruin any Attr modification optimizations on OBJECT?

What if you have this:

<object type="application/x-java-applet">
<param name="code" value"MyJavaClass">
</object>

and change the value of the param to MyNewJavaClass so that you get:

<object type="application/x-java-applet">
<param name="code" value"MyNewJavaClass">
</object>

, how would you be able to reinitialize the object unless you do
obj.type = obj.type for example. Would you be forced to change it to
something else and then change it back?

> > var obj = document.getElementsByTagName("object")[0];
> > obj.addEventListener("DOMAttrModified", function(e) {
> >
>
>  Note that setting an attribute to the value it already has doesn't fire
> DOMAttrModified in at least some UAs, so this pseudo-code doesn't quite
> match your prose description.

Thanks.

> > Opera and Firefox currently support reinitializing an object when you
> > change the type. However, it only works in certain cases.  Switching
> > an object to a Java applet from the Windows media plugin is an example
> > of one situation that doesn't work.
> >
>
>  Assuming we're talking about Firefox 3 (which handles this very differently
> from Firefox 2; I don't even remember what Firefox 2 does, exactly), type
> attribute changes do not cause any reinitialization.  This can be changed,
> of course.

I was referring to FF2 mainly. 3 beta 5 crashes with:

<head>
<script>
HTMLObjectElement.prototype.addParam = function(name, value) {
   var p = this.ownerDocument.createElement("param");
   p.setAttribute("name", name);
   p.setAttribute("value", value);
   this.appendChild(p);
};
window.addEventListener("DOMContentLoaded", function() {
   var obj = document.body.getElementsByTagName("object");
   obj[0].width = "40";
   obj[0].height = "40";
   obj[0].textContent = "You need Java!";
   obj[0].addParam("code", "JavaAppletTest");
   obj[0].setAttribute("type", "application/x-java-applet");
   obj[0].parentNode.replaceChild(obj[0].cloneNode(true), obj[0]);
   obj[0].style.width = "200px";
}, false);
</script>
</head>
<body>
<object type="application/x-mplayer2" width="300" height="300">
   <param name="ShowStatusBar" value="1">
   You need WMP!
</object>
</body>

(when application/x-mplayer2 is handled by the videolan plugin at least)

, so I haven't been able to test much with it. Need to check the latest trunk.

What is your opinion on making it so type and data changes don't
reinitialize and having a reinitialize() function instead?

var obj = document.getElementById("test");
obj.type = "something";
obj.reinitialize();

Or, if that might intefere with plugins, what about putting it just on
the object contructor like this:

var obj = document.getElementById("test");
obj.type = "something";
HTMLObjectElement.reinitialize(obj);

I really like the idea of just changing everything I want and then
explicitly calling a reinitialize when I'm ready.  Then, if I actually
wanted data or type modifications to cause a reinitialization, I could
override them to call reinitialize().

Also, in the HTML example above where it's necessary to clone and
replace to get things to work right, I use a live list so obj[0]
points to the new element in the document after the replacement.

However, if I did the following:

var obj = document.getElementById("test");
obj.type = "something";
obj.parentNode.replaceChild(obj.cloneNode(true), obj);

, after doing the replacement, 'obj' would no longer point to the
right object and I would have to manually update 'obj'.  As an
implementor, is it trivial for you to solve this problem *IF* it was
necessary to go that route?

Thanks

-- 
Michael
Received on Wednesday, 23 April 2008 19:32:00 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:16:16 GMT