Uncaught TypeError: undefined is not a function Chrome not working

Uncaught TypeError: undefined is not a function Chrome not working

我有一个启动小程序的应用程序。当我尝试单击 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 行(未捕获的类型错误:undefined 不是函数):

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

    }

第 1257 - 1281 行 engine.js

/** @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;
    }
  }
};

实在想不明白为什么是undefined。就像它无法控制小程序一样,所以没有意识到它已加载。适用于 IE8。如果有人可以阐明它。

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

第一个解决方案是简单地在小程序初始化阶段之前放置一个延迟:

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

但你不能总是确定延迟是否足够。 更复杂的解决方案可能是最多循环多次(例如 20 次),调用 init 方法,直到无法访问(即不是 "undefined"),等待一段时间(例如 125 毫秒)之前正在重试。