未捕获的TypeError:undefined不是Chrome无法正常工作的功能

时间:2015-03-31 08:12:13

标签: java javascript google-chrome dwr

我有一个应用程序启动applet。当我尝试点击Chrome中的登录按钮时,我收到以下错误

applet.htm:54 Uncaught TypeError: undefined is not a function
engine.js:1262 console.trace()
engine.js:1262 dwr.engine._debug
engine.js:1263 Error: TypeError, undefined is not a function

代码applet.htm第54行(Uncaught TypeError:undefined不是函数):

function initApplet() {
    while(ctiApplet.isActive()==false) {

    }

engine.js的第1257-1281行

/** @private Used internally when some message needs to get to the     programmer */
dwr.engine._debug = function(message, stacktrace) {
  var written = false;
  try {
    if (window.console) {
      if (stacktrace && window.console.trace) window.console.trace();
      window.console.log(message);
      written = true;
    }
    else if (window.opera && window.opera.postError) {
      window.opera.postError(message);
      written = true;
    }
  }
  catch (ex) { /* ignore */ }

  if (!written) {
    var debug = document.getElementById("dwr-debug");
    if (debug) {
      var contents = message + "<br/>" + debug.innerHTML;
      if (contents.length > 2048) contents = contents.substring(0, 2048);
      debug.innerHTML = contents;
    }
  }
};

真的无法理解为什么它是未定义的。它就像它无法抓住applet所以没有实现它的加载。适用于IE8。如果有人能说清楚它。

1 个答案:

答案 0 :(得分:1)

Call Applet.getMethod() with javascript throws error msg : TypeError: Applet.getMethod() is not a function有一个类似的问题和答案,关于Firefox,但问题是相同的:在applet初始化之前可能会发生页面完成。

第一个解决方案是在applet init阶段之前简单地延迟:

$(document).ready(function() {
    console.log("document ready");
    setTimeout(function() {
        console.log("calling openSession...");
        document.myApplet.openSession();
    }, 2000);
});

但你无法确定延迟是否足够。 一个更复杂的解决方案可能是最多次数(例如20次),调用init方法,直到这不可访问(即不是&#34;未定义&#34;),等待一段时间(例如125) ms)重试之前。