首页 > 解决方案 > 使用javascript在qml webview中加载页面时出错

问题描述

我有一个 qt quick 2 应用程序。我正在使用 qml WebView 加载页面


        WebView {
            id: webview
            onUrlChanged: {
            }
            onLoadingChanged: {
                if (loadRequest.status == WebView.LoadStartedStatus) {
                    console.log("Load start");
                } else if (loadRequest.status == WebView.LoadSucceededStatus) {
                    webview.runJavaScript("document.documentElement.innerHTML",function(result){console.log(result);});
                } else if (loadRequest.status == WebView.LoadFailedStatus) {
                    console.log("Load failed: " + loadRequest.url + ". Error code: " + loadRequest.errorString)
                }
            }
            onStateChanged: {
                console.log("** state changed-> "+webview.state);
            }
        }

我将网址设置https://website.com/user-account/entrypoint/index.html#_formname=passwordRecovery为加载页面

但我在应用程序输出中看到以下错误并且页面未加载:

Uncaught SyntaxError: Unexpected token '<'
[12984:11328:0625/163955.870:INFO:CONSOLE(1)] "Uncaught SyntaxError: Unexpected token '<'", source: https://website.com/user-account/gwt/entrypoint/entrypoint.nocache.js (1)
[12984:11328:0625/163955.870:INFO:CONSOLE(1)] "Uncaught SyntaxError: Unexpected token '<'", source: https://website.com/user-account/gwt/entrypoint/entrypoint.nocache.js (1)

加载的html是

<head>\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n\t<meta name=\"gwt:property\" content=\"locale=fa\">\n\t<script language=\"javascript\" src=\"entrypoint.nocache.js\"></script>\n</head>\n<body>\n\t<div id=\"busyStatus\"></div>\n\t<div id=\"header\"></div>\n\t<div id=\"messageContainer\"></div>\n\t<div id=\"content\" style=\"width: 97%;\"></div>\n\t<div id=\"footer\"></div>\n\n    <!-- RECOMMENDED if your web app will not function without JavaScript enabled -->\n    <noscript>\n      <div style=\"width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif\">\n        Your web browser must have JavaScript enabled\n        in order for this application to display correctly.\n      </div>\n    </noscript>\n\n    <iframe src=\"javascript:''\" id=\"__gwt_historyFrame\" tabindex=\"-1\" style=\"position:absolute;width:0;height:0;border:0\"></iframe>\n\n\n\n</body>

在已加载页面中,此消息Your web browser must have JavaScript enabled in order for this application to display correctly 我认为 WebView 存在错误,因为此页面是在 google chrome 中加载的。

标签: javascriptqtwebviewqmlqtquickcontrols2

解决方案


推荐阅读