Question

Excuse my lack of knowledge in many fundamental areas, but I am just learning how to create applets in java and how to allow interaction between the applet and the web page (javascript).

At the moment I have an applet with an init() and method1(). method1() just returns a string.

The applet is loaded on a web page and in javascript I literally reference the function:

<html>
<head>
<title>Testing Applet</title>
<script>
function hello() {

    result = document.wplayer.method1();
    alert(result);

}
</script>

</head>
<body>
<applet  code = "player.Player" name = "wplayer" archive = "player.jar" width = "600"     height = "400">

</applet>

<button onClick="hello();">Interact with app</button>

method1() just returns a string ("blah blah blah");

My question is, is this a safe way to do it and is it the most compatible?

Thanks!

Nick

Was it helpful?

Solution

is this a safe way to do it and is it the most compatible?

It's only as safe as the client is safe, so you should assume that the client may edit/forge/hack, etc.

If you meant safe in the other sense - not causing conflict - use an Object as your namespace in JavaScript and have everything kept within that Object. This way you are much less likely to have trouble with any conflicting variable names elsewhere on a page. You may also want to use unobtrusive JavaScript, to keep your script and HTML independent of each other.

Currently, your function hello is in the global namespace, and creates a global result, which could cause conflicts.

Assuming that the client has an up-to-date copy of Java and plugins enabled, you only really need to worry about the same compatibility issues as when writing any normal JavaScript for any browser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top