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:
Applet was compiled by using JDK 8
.
The main problem behind this task was that Last versions of Firefox, Chorme and Safari does not support applets and they wont launch them
The only browser that is still can launch applets is Internet Explorer and it also requires explicit permissions which are considered very dangerous.