我想知道在执行window.onload
之后是否有办法获取webEngine.executeScript
事件?
也就是说, 我有这样的javaFX代码:
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
State oldState = (State) oldValue;
State newState = (State) newValue;
System.out.printf("%s -> %s", oldValue, newValue).println();
if (newState == State.SUCCEEDED) {
window = (JSObject) webEngine.executeScript("window");
JavaBridge bridge = new JavaBridge();
window.setMember("java", bridge);
webEngine.executeScript(String.format("fct('%s')", attr.toString()));
}
}
});
webEngine.load(getClass().getResource("test.html").toExternalForm());
和javascript代码:
function f1() {
alert("window.onload");
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center : {
lat : -34.397,
lng : 10.644
},
zoom : 8
});
//This does nothing triggers
map.addDomListener(window, "load", f1);
window.onload = f1;
}
function fct(attr) {
var script = document.createElement('script');
document.getElementsByTagName('head')[0].appendChild(script);
script.src = "http://maps.googleapis.com/maps/api/js?key=" + attr
+ "&callback=initMap";
};
任何帮助?