I have a simple Applet class:
package com.myapp;
class MyApplet extends Applet {
public String myMethod() {
return "Hello";
}
}
I have compiled my with other my java classes into jarfile. Then I have run this jar files main class to ensure that jar is correctly created. It works.
Then I try to embed this Applet into my page:
<script type="application/javascript">
$(document).ready(function () {
console.log(document.MyApplet.myMethod())
});
</script>
<applet archive="myjar.jar" code="com.myapp.MyApplet.class" id="MyApplet" name="MyApplet" width=100 height=100></applet>
This throws me this error:
Uncaught TypeError: Cannot read property 'myMethod' of undefined
Which means that document.MyApplet
returns undefined
When I try to call it like this:
document.getElementById('MyApplet').myMethod();
It throws me this:
Uncaught TypeError: document.getElementById(...).myMethod is not a function
Did I miss something?
I have tested this on:
- Chrome 57.0.2987.133 (64-bit)
- Firefox 52.0.2 (32-bit)
Applet was compiled by using JDK 8
.