Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do like the idea <a href="https://stackoverflow.com/a/20255028/1155209">Stephen Katulka's</a> answer and that might be a better answer if Stephen's approach works for you.</p> <hr> <p><em>Update</em>: I just took a look at the link in <a href="https://stackoverflow.com/a/19446691/1155209">shankar's answer</a> and the code there is the same as the sample code included in this answer.</p> <hr> <p>I use the function below to utilize jQuery in WebView: </p> <pre><code>/** * 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 &gt; 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 &amp;&amp; (!(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 + "});" ); } </code></pre> <p>The function originates from this <a href="https://gist.github.com/jewelsea/3077942" rel="nofollow noreferrer">sample gist</a> to inject jQuery into a document loaded into a WebView. </p> <p>Note that the function requires the document to be loaded into the WebView before executing the script to inject jQuery. You can ensure that the document has been loaded by adding a listener to the WebEngine's document property and only triggering the function to inject jQuery once the document has been set.</p> <hr> <p>You can also include the jQuery references directly in the loaded html rather than injecting them. An example of a direct inclusion technique is this example which displays a <a href="https://gist.github.com/jewelsea/1422815" rel="nofollow noreferrer">jQuery DatePicker</a> in a JavaFX WebView screen.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload