从调用applet的JavaScript方法时出错 [英] Error when calling javascript method from applet

查看:230
本文介绍了从调用applet的JavaScript方法时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打电话给使用 netscapte.java.JSObject 从applet JavaScript方法。

I am trying to call javascript method from an Applet using netscapte.java.JSObject.

在小程序:

JSObject window = JSObject.getWindow(this.Class); 
Object[] args = ....  //arguments 
window.call("javascriptMethodName", args); 

但我得到window.call异常:

But I get the exception at window.call:


JavaScript error while calling "callFromJava"
netscape.javascript.JSException: JavaScript error while calling "callFromJava"
    at sun.plugin2.main.client.MessagePassingJSObject.newJSException(Unknown Source)
    at sun.plugin2.main.client.MessagePassingJSObject.waitForReply(Unknown Source)
    at sun.plugin2.main.client.MessagePassingJSObject.call(Unknown Source)
    at TextBoxApplet.jButton1_actionPerformed(TextBoxApplet.java:57)
    at TextBoxApplet.access$000(TextBoxApplet.java:16)
    at TextBoxApplet$1.actionPerformed(TextBoxApplet.java:36)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

JSObject 不是。有没有人遇到这样?
非常感谢。

The JSObject is NOT null. Have anyone encountered this ? Thanks a lot.

推荐答案

我做了一个快速测试,我的表现与 musicfreak <相关性良好/ A>的评论。

I did a quick test and my findings correlate well with musicfreak's comment.

通过以​​下小程序:

public class MyClass extends JApplet {
    public void init() {
        JSObject window = JSObject.getWindow(this); 
        Object[] args = new String[] { "bar" }; 
        window.call("foo", args); 
    }
}

和以下标记(注意,错误的Ja​​vaScript - 有在的说法,我没有巴兹方法传球):

and the following markup (notice the erroneous JavaScript - there's no baz method in the bar argument I'm passing):

<html>
  <head>
    <title>MyAppletTest</title>
  </head>
  <body>
    <script type="text/javascript">
      function foo(bar) { bar.baz(); }
    </script>
    <applet code="MyApplet.class"></applet>
  </body>
</html>

我得到的错误:

netscape.javascript.JSException: JavaScript error while calling "foo"
    at sun.plugin2.main.client.MessagePassingJSObject.newJSException(Unknown Source)
    at sun.plugin2.main.client.MessagePassingJSObject.waitForReply(Unknown Source)
    at sun.plugin2.main.client.MessagePassingJSObject.call(Unknown Source)
    at MyApplet.init(MyApplet.java:13)

如果我修理更换我的JavaScript函数 bar.baz()警报(巴)例如,一切工作正常。

If I fix my JavaScript function by replacing bar.baz() with alert(bar) for example, everything works fine.

长话短说 - 再看看你试图调用JavaScript函数,以及参数的小程序通过与呼叫

Long story short - take another look at the JavaScript function you are trying to call, as well as the parameters your Applet passes with the call.

这篇关于从调用applet的JavaScript方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆