This example shows how to call javascript from java applet.You
can do five simple steps to get the
result:
1. Insert "mayscript" attribut in the applet tag:
<applet codebase = "." code = "Applet1.class" name = "TestApplet" width =
"400" height = "300" mayscript>
</applet>
2.Download
winsdk40. Copy netscape directory from java_30.zip from this sdk to the
directory where you compile your files.
3. Import netscape.javascript.JSObject in your applet.
4. Use JSObject to get browser window object:
JSObject win = JSObject.getWindow(this);
5. Use eval method of this object:
win.eval("alert('friends')");
See Example of calling javascript alert() from applet
See Java code of this example
|