【问题标题】:Uncaught TypeError: undefined is not a function Chrome not workingUncaught TypeError: undefined is not a function Chrome not working
【发布时间】:2015-03-31 08:12:13
【问题描述】:

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

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;
    }
  }
};

真的无法理解为什么它是未定义的。就像它无法控制小程序一样,因此没有意识到它已加载。适用于 IE8。如果有人能对此有所了解。

【问题讨论】:

    标签: java javascript google-chrome dwr


    【解决方案1】:

    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 方法,直到它无法访问(即不是“未定义”),等待一段时间(例如 125 毫秒),然后重试。

    【讨论】:

    • 谢谢,是的,这似乎是最好的解决方案。有时它有效,有时我得到上述错误,所以延迟是最好的。
    猜你喜欢
    • 1970-01-01
    • 2014-08-15
    • 2015-01-14
    • 2014-07-06
    • 2014-09-01
    • 2015-11-04
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多