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 20:08:16 -0400
Message-ID: <6b9c91b20804231708o3b2946e8u62335ee218745f0a@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:
> > 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?
> >
>
>  I'm not quite sure what you're asking here.

I'll clarify.

Attached is reinit.html.

The reinitialize prototype function is how I would solve the whole
thing using just a little JS.

The function clones the object, inserts the clone before the existing
object, removes the existing object and returns a ref to the newly
inserted object (or returns the existing object if it doesn't have a
parentNode).

The reason I do it that way is because it works really well. Since
it's a whole new object getting inserted, the browser has no problem
evaluating it. It works great in Opera, Firefox and Safari and this
way, there's no need to type or data changes to cause a
reinitialization.

But, as you see, I need to do:
obj = obj.reinitialize();
to update what 'obj' points to if I want to use 'obj' after reinitializing.

What I was asking is, if you implemented a reinitialize() for OBJECT
natively that did the clone, insert, remove deal just like I did,
would you have any trouble making it so I wouldn't have to do:
obj = obj.reinitialize()
and instead could do just:
obj.reinitialize();
and still make 'obj' point to the new object?

In other words, if the reinitialize function() didn't return anything,
would you be able to make it automatically update 'obj' internally?
Or, would that not be possible?

The reason I ask is, my reinitialize function works great and the idea
might be worth considering, but it would be much better if the author
didn't have to reassign 'obj' manually like that.

Now, if you can get the same behavior without doing the clone + insert
+ replace and leave the obj ref in tact, I guess this doesn't matter.

Thanks

-- 
Michael


Received on Thursday, 24 April 2008 00:08:52 UTC

This archive was generated by hypermail 2.3.1 : Monday, 29 September 2014 09:38:54 UTC