Important: Please read the Qt Code of Conduct -

Multiple evaluatejavascript calls causing javascript Type Error (JQuery)

  • If I have my application execute back to back evalutatejavascript calls using the same frame object, the second call always throws a javascript TypeError: Type error message.

    If I combine all the javascript/jquery into one evaluatejavascript call, then it works fine. Which is what I am going to do. But, the issue has me concerned since evaluatejavascript is used quite a bit in our application.

    @streamJavascript("$("#on-screen-time").text("" + hourMinAmPmPattern.cap(1) + "");");
    streamJavascript("$("#on-screen-ampm").text("" + hourMinAmPmPattern.cap(2) + "");");

    void AdiTimeManager::streamJavascript(QString javascript)
    QString sJavaScript;
    QTextStream streamJavascript(&sJavaScript);
    streamJavascript << javascript;
    ADIGlobal::sendJavascript(frame, sJavaScript);

    void ADIGlobal::sendJavascript(QWebFrame *frame, QString sJavascript)
    if ( sJavascript != "" )
    if ( Log4Qt::Logger::logger("ADIGlobal") )
    Log4Qt::Logger::logger("ADIGlobal")->debug() << "sendJavascript " << sJavascript;

    08:38:16.135 DEBUG [ADIGlobal] sendJavascript $("#on-screen-time").text("8:38");
    08:38:16.225 DEBUG [ADIGlobal] sendJavascript $("#on-screen-ampm").text("AM");
    08:38:16.225 DEBUG [AdiWebPage] TypeError: Type error
    08:38:16.225 DEBUG [AdiWebPage] 1:@

  • Update.

    Apparently, this has nothing to do with multiple calls. All calls are throwing the error, but after every other evaluatejavascript call.

  • I found a work around.. however I dont have any idea why it works. There is a form element further down the page:

    @<form><input type="button" class="ENTER" /></form>@

    When changing the input type to "text" it everything works fine. Luckily, the input type doesn't matter for me.

    I really have no idea why this would matter.

Log in to reply