当前位置: 首页 > 知识库问答 >
问题:

尝试将JQuery注入JavaFx WebView时出现意外标记“

陈扬
2023-03-14

基本上,我需要获取字符串形式的数据(与问题无关),并通过jQuery将其追加到JavaFx WebView中。在此链接中,我找到了如何嵌入Jquery并将Jquery函数调用到WebView:https://community.oracle.com/message/10446280?tstart=1.'

HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView("com.interpro.emmeclipse.views.PageBuilderPart");

                FXSceneProvider view = (FXSceneProvider) page.findView("com.interpro.emmeclipse.views.PageBuilderPart");
                Scene scene = (Scene) view.getScene();
                AnchorPane node = (AnchorPane)scene.getRoot();
                WebView webview = (WebView) node.getChildren().get(0);
                final WebEngine engine = webview.getEngine();



                final IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
                if (activeEditor != null) {
                    final IDocument doc = (IDocument) activeEditor.getAdapter(IDocument.class);
                    if(doc != null){
                        System.out.println(doc.get());
                        engine.documentProperty().addListener(new ChangeListener<Document>() {
                            @Override public void changed(ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) {
                              executejQuery(
                                engine, 
                                "$(\"#content\").append(<div class='ui-statusbar'><h5 class='ui-title'>Test</h5></div>);" 
                              );
                            }
                          });
                    }
                }

/**
   * Executes a script which may reference jQuery function on a document.
   * Checks if the document loaded in a webEngine has a version of jQuery corresponding to 
   * the minimum required version loaded, and, if not, then loads jQuery into the document 
   * from the default JQUERY_LOCATION.
   * @param engine the webView engine to be used.
   * @Param jQueryLocation the location of the jQuery script to be executed.
   * @param minVersion the minimum version of jQuery which needs to be included in the document.
   * @param script provided javascript script string (which may include use of jQuery functions on the document).
   * @return the result of the script execution.
   */ 
  private static Object executejQuery(final WebEngine engine, String minVersion, String jQueryLocation, String script) {
    return engine.executeScript(
      "(function(window, document, version, callback) { "
        + "var j, d;"
        + "var loaded = false;"
        + "if (!(j = window.jQuery) || version > j.fn.jquery || callback(j, loaded)) {"
        + "  var script = document.createElement(\"script\");"
        + "  script.type = \"text/javascript\";"
        + "  script.src = \"" + jQueryLocation + "\";"
        + "  script.onload = script.onreadystatechange = function() {"
        + "    if (!loaded && (!(d = this.readyState) || d == \"loaded\" || d == \"complete\")) {"
        + "      callback((j = window.jQuery).noConflict(1), loaded = true);"
        + "      j(script).remove();"
        + "    }"
        + "  };"
        + "  document.documentElement.childNodes[0].appendChild(script) "
        + "} "
      + "})(window, document, \"" + minVersion + "\", function($, jquery_loaded) {" + script + "});"
    );
  }

  private static Object executejQuery(final WebEngine engine, String minVersion, String script) {
    return executejQuery(engine, DEFAULT_JQUERY_MIN_VERSION, JQUERY_LOCATION, script);
  }

  private Object executejQuery(final WebEngine engine, String script) {
    return executejQuery(engine, DEFAULT_JQUERY_MIN_VERSION, script);
  }
netscape.javascript.JSException: SyntaxError: Unexpected token '<'
at com.sun.webpane.platform.WebPage.twkExecuteScript(Native Method)
at com.sun.webpane.platform.WebPage.executeScript(Unknown Source)
at javafx.scene.web.WebEngine.executeScript(Unknown Source)
at com.interpro.emmeclipse.commands.OpenPageBuilder.executejQuery(OpenPageBuilder.java:102)
at com.interpro.emmeclipse.commands.OpenPageBuilder.executejQuery(OpenPageBuilder.java:123)
at com.interpro.emmeclipse.commands.OpenPageBuilder.executejQuery(OpenPageBuilder.java:127)
at com.interpro.emmeclipse.commands.OpenPageBuilder.access$0(OpenPageBuilder.java:126)
at com.interpro.emmeclipse.commands.OpenPageBuilder$1.changed(OpenPageBuilder.java:69)
at com.interpro.emmeclipse.commands.OpenPageBuilder$1.changed(OpenPageBuilder.java:1)
at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(Unknown Source)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown Source)
at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(Unknown Source)
at javafx.scene.web.WebEngine$DocumentProperty.invalidate(Unknown Source)
at javafx.scene.web.WebEngine$DocumentProperty.access$300(Unknown Source)
at javafx.scene.web.WebEngine$LoadWorker.dispatchLoadEvent(Unknown Source)
at javafx.scene.web.WebEngine$LoadWorker.access$600(Unknown Source)
at javafx.scene.web.WebEngine$PageLoadListener.dispatchLoadEvent(Unknown Source)
at com.sun.webpane.platform.WebPage.fireLoadEvent(Unknown Source)
at com.sun.webpane.platform.WebPage.fwkFireLoadEvent(Unknown Source)
at com.sun.webpane.webkit.network.URLLoader.twkDidFinishLoading(Native Method)
at com.sun.webpane.webkit.network.URLLoader.access$1300(Unknown Source)
at com.sun.webpane.webkit.network.URLLoader$6.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

线程“JavaFX应用程序线程”中出现异常

共有1个答案

燕禄
2023-03-14

我认为下一行由于缺少引号而产生错误:

"$(\"#content\").append(<div class='ui-statusbar'><h5 class='ui-title'>Test</h5></div>);" 

试试看

"$(\"#content\").append(\"<div class='ui-statusbar'><h5 class='ui-title'>Test</h5></div>\");" 
 类似资料:
  • 尝试运行lint脚本时出现问题 我不断得到这个错误提示,它似乎只发生在更新我的eslint deps符合airbnb规则(我使用) 错误: 但是,运行以下工作预期: 这是我的. eslintrc文件: 这些是我目前的eslint deps: 任何帮助将是伟大的!非常感谢!

  • 问题内容: 我正在尝试使用JAXB将以下XML映射到POJO,以便可以使用XML中的数据,但是,出现以下错误: XML: 我的POJO(故意将getter / setter从问题中跳过) ItemSearchResponse 物品 项目 项目属性 问题 我该如何解决错误?我的POJO设置不正确吗?如果是这样,我应该如何重组POJO? xml中有多个。如何将它们映射到数组或排序列表。 问题答案: 您

  • 因此,我尝试使用coinbase API。我正在尝试一个简单的测试,看看我是否可以让它工作,但我得到了各种作曲家的错误。 目前,我得到意外的t'use'为这个代码: 那么,我的使用声明在错误的地方吗?我在索引函数和类之外尝试过它们。两者产生的结果与此完全不同。 在Keks班之外,我得到了 致命错误:在第15行的/home/content/61/11420661/html/beta/applicat

  • C:\users\...\node_modules\react-native-fetch-blob\index.js:5 import{ ^^^^^^ syntaxerror:意外标记导入 在object.exports.runinthiscontext(VM.JS:76:16) 在module._compile(module.js:513:28) 在object.module.js:550:10

  • 我正在尝试在表a中插入外键(在phpmyadmin中): 将表A添加外键(id_B)引用B(id_B); 但我得到了一个错误: 表A的id_A为主键,表B的id_B为主键。这两个表都使用innoDB作为存储引擎,表A中的id_B列和表B中的id_B列具有相同的类型。 出了什么问题,我该如何解决?

  • 我正在为一个班级做一个应用程序,教授和我一样困惑为什么它不起作用。我有2个js文件和一个html。我将一个数组从一个js导出到另一个,然后在我的html中使用那个js作为src。以下是相关代码: 医疗名单。js: main.js: HTML: 下面是我得到的错误: main.js: 1未捕获的语法错误:意外令牌{ 我尝试在脚本标记中使用type="模块",但是当我尝试使用main.js中声明的函数