0

I have some java script to check if applet is finished loading before I load the rest of the page. It has worked for years, and now seems to be failing in Firefox 16 and IE 7. It works in IE 8

Any suggestions on why it has broken and what might fix it?

<applet name="env" archive="portal-applet-envir.jar" code="com/deleted/AppletEnvironment.class" height="1" mayscript="true" width="1">
</applet>
<table width="98%" align="center"><tr><td>
<script language="javascript">
function waituntilok() {
   if (document.env.isActive()) {
     doit();
  }
  else {
      var ct = 0;
      while (! document.env.isActive())
      {
      }
     doit();
   }
}
[....]
waituntilok();
</script>
</td></tr></table>

You are initialising your counters with the character position:

myMap.put(ch, i);

where you want:

myMap.put(ch, 1);

You also want to check the map for an already existing character before you initialise the counter, incrementing the counter of it does (using get(ch) not get(i)), giving:

    char ch = s.charAt(i);
    //calculating the occurence of a character in a string.
    if (myMap.containsKey(ch)){                   
        myMap.put(ch, myMap.get(ch) + 1);
    } else {
        myMap.put(ch, 1);
    }//end of if statement
4

1 回答 1

1

document.env.isActive()在小程序初始化之前调用时,FF 会注册一个“没有这样的方法”错误并退出该函数。在调试这些东西时检查错误控制台是值得的。

同样可疑的是 1x1 的小程序大小。有些工具旨在保护用户,这些工具将删除“可疑的小”HTML 元素。

此版本适用于 FF。在 IE 和 FF 中尝试并报告回来。

<html>
<body>
<applet
    name="env"
    archive="http://pscode.org/lib/mime.jar"
    code="org.pscode.mime.MimeType"
    height="100"
    mayscript="true"
    width="600">
</applet>
<table width="98%" align="center">
<tr>
<td>
<script language="javascript">
function waituntilok() {
    if (document) {
        alert('document');
    }
    if (document.env) {
        alert('document.env');
    }
    if (document.env.isActive()) {
        doit();
    } else {
        var ct = 0;
        while (! document.env.isActive())
        {
        }
        doit();
    }
}

function doit() {
    alert('Just Do It!');
}

setTimeout('waituntilok()', 15000);
</script>
</td>
</tr>
</table>
</body>
</html>
于 2012-11-16T14:49:50.470 回答