JSObject を使用して、アプレットから Javascript 関数を呼び出しています。
私のアプレットのSSCCE:
package ch.vrag.web;
import java.applet.Applet;
import java.security.AllPermission;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.Policy;
import netscape.javascript.JSObject;
public class Sscce extends Applet {
private static final long serialVersionUID = -5403444704039831864L;
public void init() {
try {
Policy.setPolicy(new Policy() {
Permissions perms = new Permissions();
public PermissionCollection getPermissions(CodeSource codesource) throws SecurityException {
AllPermission grant = null;
grant = new AllPermission();
perms.add(grant);
return perms;
}
public void refresh() {
// Do nothing
}
});
}
catch (Exception e) {
}
JSObject window = JSObject.getWindow(this);
JSObject phoneNums = (JSObject) window.eval("getWindowRectangle()");
int x;
int y;
int width;
int height;
if (phoneNums.getSlot(0) instanceof Integer) {
x = (Integer) phoneNums.getSlot(0);
y = (Integer) phoneNums.getSlot(1);
width = (Integer) phoneNums.getSlot(2);
height = (Integer) phoneNums.getSlot(3);
}
else if (phoneNums.getSlot(0) instanceof Double) {
x = ((Double) phoneNums.getSlot(0)).intValue();
y = ((Double) phoneNums.getSlot(1)).intValue();
width = ((Double) phoneNums.getSlot(2)).intValue();
height = ((Double) phoneNums.getSlot(3)).intValue();
}
else {
return;
}
System.out.println("x: " + x + " y: " + y + " width: " + width + " height: " + height);
};
}
私の HTML ファイルの SSCCE:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">
function getWindowRectangle(){
var winX = (document.all)?window.screenLeft-2:window.screenX;
var winY = (document.all)?window.screenTop-2:window.screenY;
var winWidth = (document.all)?document.documentElement.offsetWidth+4:window.outerWidth;
var winHeight = (document.all)?document.documentElement.offsetHeight+4:window.outerHeight;
return([winX,winY,winWidth,winHeight]);
}
</script>
<title>SSCCE</title>
</head>
<body>
this is an SSCCE
<APPLET CODE="ch.vrag.web.Sscce.class" name="SSCCE" codebase="scripts" archive="Sscce.jar" width=0 height=0 MAYSCRIPT >
</APPLET>
</body>
これは、Internet Explorer 6 でうまく動作します。そこには、次の Java 例外があります。
java.lang.Exception: netscape.javascript.JSException: Unknown Name
この例外は何に適していますか? 私は何を間違っていますか?