Unable to access Applet methods from javascript

A

anonymous

This is what I'm doing. It works in Netscape but doesn't work in IE
6. I thought it should, any ideas?

File: FirstApplet.java
----------------------

import java.applet.Applet;

public class FirstApplet extends Applet {
public String firsttest() {
return "Hello World";
}
}


File: test1.html
----------------

<html><body>
<APPLET
NAME="myapplet"
CODEBASE="."
CODE="FirstApplet.class"
WIDTH=1
HEIGHT=1>
</APPLET>
<script>
var answer = document.myapplet.firsttest();
alert ( answer );
</script>
</body></html>
 
A

Andrew Thompson

| This is what I'm doing. It works in Netscape but doesn't work
in IE
| 6. I thought it should, any ideas?

I am not surprised it does not work*,
Browser support for such features is
often patchy. AFAIU it was Netscape
that is mostly responsible for JavaScript,
and they developed the API for Java/JS
interaction.

Does it work in Opera?

* And for those that know me well,
I better add that this is one of the
_few_ times that I will not blame MS!
 
I

Ike

Thats Right. Why run in the MS JVM ???? Let the Sun plugin run it in MSIE,
and allow for the javax packages. -Ike
 
J

JScoobyCed

Well, I have an applet (JApplet, but that doesn't change anything) that is
called by a JavaScript. There are something to consider:
you have to wait the applet is completely loaded and instancied before JS
can access it. For example use a button:
<APPLET name="myapplet" codebase="." code="FirstApplet" width="1"
height="1">
</APPLET>
<input type="button" value="Test JS"
onclick="javascript:alert(document.myapplet.firsttest())">

I compiled your code and use the above code in a html file, it works on IE
5(Win98) and IE 6(Win2000)

JScoobyCed
-------------
 
A

anonymous

Thanks JScoobyCed, it was a timing issue. And infact that is how I
need to use it, I don't actually need to have it run right at page
load. I wonder how you could force the upload to occur or test that
it has happened and wait for it. Any ideas?

Thanks,

Fenton
 
A

Andrew Thompson

| Thanks JScoobyCed, it was a timing issue.
.....
.....
| > onclick="javascript:alert(document.myapplet.firsttest())">

I suggest one of two strategies.
a) define an attribute in the applet that starts out
"null", and set it to "loaded" at the end of init().
Use JavaScript to get it. If it is undefined or
"null" the applet is not ready.
b) get firsttest to return a 'true' when it completes
successfully, and test _that_ in the JS..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top