jQuery 및 Java 애플릿
-
09-06-2019 - |
문제
저는 UI의 일부(특히 지도)에 Java 애플릿을 사용하고 나머지 UI는 HTML/JavaScript로 애플릿 주위에 구축하고 LiveConnect/NPAPI를 통해 애플릿과 통신하는 프로젝트를 진행하고 있습니다. .조금 이상하다는 건 알지만 설정에 대해서는 논의 중이 아니라고 가정해 보겠습니다.저는 jQuery를 JavaScript 프레임워크로 사용하려고 계획을 시작했지만 두 가지 문제에 직면했습니다.
첫 번째 발행:
애플릿을 선택해도 애플릿의 메소드에 대한 액세스는 제공되지 않습니다.
자바:
public class MyApplet extends JApplet {
// ...
public String foo() { return "foo!"; }
}
자바스크립트:
var applet = $("#applet-id");
alert(applet.foo());
위의 JavaScript를 실행하면 다음과 같은 결과가 나타납니다.
$("#applet-id").foo is not a function
이는 유사한 코드가 작동하는 Prototype과 대조됩니다.
var applet = $("applet-id");
alert(applet.foo());
그럼...애플릿 메소드는 어디로 갔나요?
두 번째 발행:
Firefox 2의 jQuery 및 애플릿에는 알려진 문제가 있습니다. http://www.pengoworks.com/workshop/jquery/bug_applet/jquery_applet_bug.htm
긴 기회이지만 해결 방법을 아는 사람이 있습니까?이 문제는 고칠 수 없을 것 같습니다. 이는 Prototype으로 전환하는 것을 의미합니다.
도와 주셔서 감사합니다!
해결책
첫 번째 문제는 시도해 보는 것이 어떻습니까?
alert( $("#applet-id")[0].foo() );
두 번째 문제는 다음과 같습니다. 실 가능한 해결 방법이 있습니다.
해결 방법 인용
// Prevent memory leaks in IE // And prevent errors on refresh with events like mouseover in other browsers // Window isn't included so as not to unbind existing unload events jQuery(window).bind("unload", function() { jQuery("*").add(document).unbind(); });
해당 코드를 다음으로 변경하십시오.
// Window isn't included so as not to unbind existing unload events jQuery(window).bind("unload", function() { jQuery("*:not('applet, object')").add(document).unbind(); });
제휴하지 않습니다 StackOverflow