views:

57

answers:

3

I want to embed both an ActiveX and NPAPI plugins in one page using nested object tags (as recommended by Mozilla) instead of relying on user agent.

The problem is: I want to use one object id, such as id="MyObject", which will be defined in both object tags (for the ActiveX or NPAPI) so that my Javascript calls the object MyObject directly regardless of whether it is an ActiveX or NPAPI.

I hope I made myself clear.

+1  A: 

Well, you should not do that. Instead, give the objects the same "class" value, and have your Javascript look for that.

Values for "id" attributes must be unique.

Pointy
And how do I go on about doing that? Both object tags have a class value, ok no problem with that, but how can I get the object to be global among all Javascript functionality, and how can I get the element by its class?
Voulnet
For example:<object classid="clsid:something" class="myClass"><object type="application/x-blah-blah-blah" class="myClass" > </object> </object>Then what, somewhere in my Javascript I call:objectx = getElementsByClassName('myClass');Because that doesn't work right.
Voulnet
Yes, that's exactly how you'd do it, and it will "work right". It's an extremely common way to do things.
Pointy
Sorry, but it didn't work. Not many browsers support that method, and even in FF3.6.10 it didn't work although I did in fact define a custom getElementsByClassName function in case the browser doesn't support it. But I found another solution. Thanks for the great effort, though.
Voulnet
Well you can get elements other ways too, you know. You could, for example, call "getElementsByTagName('*')" and then iterate through the node list looking for the ones you want.
Pointy
A: 

getElementsByClassName didn't work for me, so I did a simple trick that worked beautifully.

<object classid="clsid:something" id="obj1" >
<object type="application/x-blah-blah-blah" id="obj2">
</object></object>

Then in my JavaScript code I called at the beginning:

if (obj2!=null && obj2!=undefined)

or if you wish if (!(obj2==null || obj2==undefined)) whatever you like

obj1 = getElementById("obj2");

That will create the object for the NPAPI plugin, or if the browser is IE, will proceed smoothly without entering that if statement (IE doesn't allow you to use getElementById to assign to an object that has an id attribute). Then you just use obj1 for your processing or use it to instantiate another object as you see fit.

Voulnet
A: 

You can actually register a mime type for an activex control, if it's yours, which then would allow you to use the same object tag for both.

FireBreath (http://firebreath.org) does this.

More info here: http://msdn.microsoft.com/en-us/library/aa751976(VS.85).aspx

Taxilian
That doesn't sound so standard-y, so I used what YouTube does. I check if the browser is IE then based on that I dynamically inject into the DOM.
Voulnet
Also, thank you so much for your GREAT work at ColonelPanic, man! Your NPAPI tutorials are made of pure win.
Voulnet
I'm glad they're helpful =] It really isn't uncommon to register the mime type, but either way works. There are advantages and disadvantages both directions.
Taxilian