0
JxBrowser를 사용하여 Java Javascript 브리지를 설정하려고합니다. onScriptContextCreated
메서드가 호출되지 않아 그 이유가 확실하지 않습니다.JxBrowser onScriptContextCreated가 호출되지 않습니다.
Java 응용 프로그램에 브라우저가 내장되어 있으며 버튼을 클릭하면 "howdy"가 표시되지만 "hello"는 Java 콘솔에 인쇄되지 않습니다. 나는 onScriptContextCreated
방법으로 디버그 라인을 던져 버렸고 절대로 안타.
다음은 자바 코드 여기
webBrowser.addScriptContextListener(new ScriptContextAdapter() {
@Override
public void onScriptContextCreated(ScriptContextEvent event) {
Browser browser = event.getBrowser();
JSValue window = browser.executeJavaScriptAndReturnValue("window");
System.out.println("Setting property");
window.asObject().setProperty("sendNSCommand", new JSFunctionCallback() {
@Override
public Object invoke(Object... os) {
String command = (String) os[0];
System.out.println("Command from JavaScript: " + command);
return null;
}
});
}
});
그리고이 코드 예제가 제대로 작동처럼
<html>
<head>
<script>
function callMe() {
sendNSCommand2("howdy");
sendNSCommand("hello");
}
function sendNSCommand2(x) {
window.alert(x);
}
</script>
</head>
<body>
<input type="button" value="test" onClick="callMe()" />
</body>
</html>