使用 JavaFX 小程序:
我使用 document.getElementById("APPLET_ID") 获得的 javascript 对象在 Windows 下没有 Packages 属性。我使用最新的 IE8、FF 和 Chrome 在 Windows XP 上运行测试,但在 Windows 7 下出现同样的问题。
在带有 JRE 7u7 x64 的 Ubuntu 下,没有这样的问题。
这是我的测试代码:
package test;
import netscape.javascript.JSObject;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Main extends Application {
private JSObject js;
TextField tf;
@Override
public void start(Stage primaryStage) {
js = this.getHostServices().getWebContext();
HBox hb = new HBox();
Scene s = new Scene(hb, 400, 400);
tf = new TextField("MAIN");
primaryStage.setScene(s);
hb.getChildren().add(tf);
primaryStage.show();
runTest();
}
public static void main(String[] args) {
launch(args);
}
void runTest(){
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Platform.runLater(
new Runnable() {
@Override
public void run() {
tf.setText("" + js.eval("document.getElementById('applet_id').Packages == null"));
}
}
);
}
}).start();
}
}
在 Ubuntu JRE7u7x64 下显示“false”,在所有浏览器的 Windows 和 Ubuntu JRE7u21 下显示“true”。
正如 JavaFX2 部署文档页面告诉我以正确的方式做的那样,它看起来像一个 JRE 错误。你怎么看待这件事 ?
http://docs.oracle.com/javafx/2/deployment/javafx_javascript.htm。
归档在 Jira 上: https ://javafx-jira.kenai.com/browse/RT-30732