我同意朱利安的观点。
只需创建您自己的浏览器扩展默认浏览器并扩展它并声明一个 JavaScript 回调函数:
public class MbBrowserEditor extends DefaultBrowserEditor {
...
public void createPartControl(Composite parent) {
super.createPartControl(parent);
this.registerJavaScriptCallback(new MbJavascriptCallback(this), "callSWS");
}
...
}
registererd JavaScriptCallback 可能是这样的:
public class MbJavascriptCallback extends JavaScriptCallback {
MbBrowserEditor browserView = null;
// javascript callback function name
String sbMergeBack = "callBackFromPnrMb";
// parameters for the javascript callback function
String sSuccess = "true";
String sMessage = "PNR Merge Back executed successfully";
String sErrorDetail = "No error";
...
/**
* this function will be called by JS to execute a SWS workflow
* it expects the following parameters :
* items : an array of strings
* transactions : an array of strings
* cbMergeBack : a string
*/
@Override
public void function(Object[] arguments) {
// do your stuff
callBackWebApp();
}
private void callBackWebApp() {
...
// callback javascript (with 3 params - set your own)
final String cbFunction = sbMergeBack+"(\"" + sSuccess + "\", \"" + sMessage + "\", \"" + sErrorDetail + "\");";
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
...
try {
browserView.executeJavaScript(cbFunction);
} catch (Exception ex) {
...
}
}
});
}
...
}
在这里工作得很好