我想在 DJ 原生 swing jwebbrowser 中执行我的 javascript 代码,但我应该等待页面加载,如何设置监听器?我尝试以下操作,但加载后总是运行脚本,它也运行得很晚!
webBrowser.addWebBrowserListener(new WebBrowserListener(){
@Override
public void commandReceived(WebBrowserCommandEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void locationChanging(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void statusChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
if(webBrowser.getLoadingProgress() == 100)
webBrowser.executeJavascript("some js code");");
}
@Override
public void titleChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
frame.dispose();
}
@Override
public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
// TODO Auto-generated method stub
}
});
我该怎么办?