| Author |
Javascript interaction with an applet, but what if I can't use the APPLET tag?
|
Joe Vahabzadeh
Ranch Hand
Joined: Jan 05, 2005
Posts: 129
|
|
All, I've got a web-page based application that primarily works with Javascript and HTML, but uses a java applet in the page for certain types of work. So the applet is in the page with an actual APPLET tag. If the Javascript needs to get the applet to do something, or get some information from the applet, I use the following: document.applets[0].funcName(params) However, now there's rumbling from the decision-makers as to whether or not we should move from using the APPLET tag to using OBJECT and EMBED tags. Unfortunately, a quick attempt at that shows that, surprise surprise, when I use either OBJECT (for IE) or EMBED (for everything else), I get a Javascript error saying that document.applets[0] has no properties. The convenient thing was that, for non-IE, I could just substitute "document.embeds[0]" in place of "document.applets[0]" and it works. Not so with OBJECT for IE. So, is there an equivalent that can be used when/if I have to use the OBJECT tag for IE? Thanks in advance... EDIT: Ok, I'm kind of a doofus here - although it didn't work the first time I tried it so I'm convinced the browser's conspiring against me. My results: IE: OBJECT tag, use document.applets[0].funcName Firefox: EMBED tag, use documents.embeds[0].funcName Opera: EMBED tag, both applets[0] and embeds[0] work. I don't suppose there's some universal sort of keyword here instead of embeds or applets that'll work on everything, is there? [ January 17, 2007: Message edited by: Joe Vahabzadeh ]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
Let's move this to "HTML and JavaScript" so the JavaScript gods will smile upon you.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
Can you just give the object an ID and reference that instead with: document.getElementById("myId"). Eric
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
if that does not work you can try object detection Eric
|
 |
Joe Vahabzadeh
Ranch Hand
Joined: Jan 05, 2005
Posts: 129
|
|
Eric, Thanks for the suggestions. For the first solution - works in Firefox, but not IE6 or Opera (don't have access to the Mac today to test against Safari) Looks like if management insists on conversion to OBJECT/EMBED that I'll have to go with your second solution - but I'm trying to convince them to simply keep using the APPLET tag - I don't see any real benefit to switching from APPLET over to OBJECT/EMBED, but I'll admit that I don't know a whole lot about the distinction between the two methods.
|
 |
 |
|
|
subject: Javascript interaction with an applet, but what if I can't use the APPLET tag?
|
|
|