在 ie8 和 chrome 中从 javascript 调用 java 方法

发布于 2024-09-30 05:57:38 字数 223 浏览 1 评论 0原文

我一直想知道是否有办法让以下 javascript 函数在 IE8 和 Chrome 中工作:

var funct = function()
{
var ppt = new java.awt.Point(200,100);
alert(ppt.x);
} 

这个东西只在 Firefox 中工作。有没有办法在 IE 8 和 Chrome 中启用全局 Java 包?

I have been wondering if there is a way to make the following javascript functions work in IE8 and Chrome:

var funct = function()
{
var ppt = new java.awt.Point(200,100);
alert(ppt.x);
} 

This thing works only in Firefox. Is there a way to enable global Java packages in IE 8 and Chrome?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我最亲爱的 2024-10-07 05:57:38

没有完全回答您的问题 - 但您可能会发现 GWT (http://code.google.com/webtoolkit/) 有帮助。

它允许您用 Java 编写 Web 应用程序,该应用程序被“编译”为 javascript,以便在任何现代浏览器中运行。它仅支持标准 Java 库的一个子集 - 特别是它不支持 java.awt。

Not quite answering your question - but you might find GWT (http://code.google.com/webtoolkit/) helpful.

It lets you write web applications in Java, which gets 'compiled' into javascript to be run inside any modern browser. It only supports a subset of the standard Java libraries - in particular it doesn't support java.awt.

硪扪都還晓 2024-10-07 05:57:38

嗯,就在这里。 IE 8 和 Chrome 不允许全局 java 包:
即你不能直接在 JavaScript 中使用 java.lang.String 或 java.atw.Point 。但是,如果您有一个小程序,您可以轻松地通过您的小程序公开此类。例如,如果您在小程序中导入 java.awt.Point 并具有如下方法:

public Point createPoint(int x,int y);

您现在应该能够从 javascript 访问小程序并像这样调用它的方法:

(javascript代码)

var applet = document.getElementById("applettie");
var Point = applet.createPoint(20,30);
//now you have the Point object 

干杯

Well, here it is. IE 8 and Chrome do not allow for global java packages:
i.e you cant use java.lang.String, or java.atw.Point directly in your javascript. However, if you have an applet, you can easily expose such classes through your applet. For example, if you import java.awt.Point in your applet and have a method like this:

public Point createPoint(int x,int y);

You should be able now from your javascript to access the applet and just call its method like this:

(javascript code)

var applet = document.getElementById("applettie");
var Point = applet.createPoint(20,30);
//now you have the Point object 

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文