从java小程序中调用javascript函数-Firefox与IE

从java小程序中调用javascript函数-Firefox与IE,java,javascript,internet-explorer,firefox,applet,Java,Javascript,Internet Explorer,Firefox,Applet,HTML代码: <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-15" /> <script type="text/javascript"> var foo; function test(s) { foo = s; alert(foo); } window.onload = function () { foo = 'init'; docu

HTML代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-15" />

<script type="text/javascript">

var foo;

function test(s)
{
    foo = s;
    alert(foo);
}

window.onload = function ()
{
    foo = 'init';
    document.getElementById('foo').doit();
    alert(foo);
}
</script>
<body>
<applet id="foo" code="TestApplet.class"
    archive="TestApplet.jar" width="0" height="0"></applet>
</body></html>
当我调用此HTML页面时:

  • 在IE(8)我得到:第一次弹出(“foobar”),第二次弹出(“foobar”)
  • 在Firefox中(19.2,30.0)我得到:第一次弹出(“foobar”),第二次弹出(“init”)
有人能解释为什么吗?显然,
foo
只是由小程序临时编写的


非常感谢。

此主题和答案可能会有所帮助:
public void doit ()
{
    try {
        getAppletContext().showDocument(
            new URL("javascript:test(\"foobar\")"));    
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}