Pulits
Pulits

Reputation: 33

Invoking applet method via JavaScript won't work

I am invoking methods of a Java applet via JavaScript, using the following:

document.myApplet.myMethod();

However, this only works perfectly when I add the site to trusted site and set the security to low. Otherwise, it throws me this error:

Microsoft JScript runtime error: Object doesn't support property or method 'myMethod'

How can I solve this?

Chrome prompts me if I want to execute the applet.

Full code snippet:

<html>
<head>
<script type="text/javascript">
    function getKey() {
    var key = document.myApplet.mymethod();
    }
</script>
</head>
<body onload="getKey()">
<applet id="myApplet" archive="myApplet.jar" code="myApplet.class" width="0" height="0"></applet> 
</body>
</html>

Upvotes: 2

Views: 4201

Answers (1)

Suave Nti
Suave Nti

Reputation: 3747

Use an Object tag instead of applet tag like this

 <object type="application/x-java-applet" width="0" height="0" name="appId">
        <param name="code" value="myApplet" />
        <param name="archive" value="myApplet.jar" />   
 </object>

And your Javascript like this:

function getKey() {
   var key = appId.mymethod();
}

Upvotes: 1

Related Questions