Java Code Examples for javafx.scene.web.WebEngine#executeScript()

The following examples show how to use javafx.scene.web.WebEngine#executeScript() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextEditorPane.java    From logbook-kai with MIT License 6 votes vote down vote up
private void setting() {
    WebEngine engine = this.webview.getEngine();
    JSObject window = (JSObject) engine.executeScript("window");
    Object ace = null;
    try {
        ace = engine.executeScript("ace");
    } catch (Exception e) {
    }
    if (ace != null && ace != engine.executeScript("undefined")) {
        if (this.lang != null) {
            window.call("start", this.lang);
            this.lang = null;
        }
        if (this.source != null) {
            window.call("set", this.source);
            this.source = null;
        }
        if (this.readOnly != null) {
            window.call("setReadOnly", this.readOnly);
            this.readOnly = null;
        }
    }
}
 
Example 2
Source File: JavaFXBrowserWithHistory.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
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 + "});");
}
 
Example 3
Source File: NetworkTools.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> readCookie(WebEngine webEngine) {
    try {
        String s = (String) webEngine.executeScript("document.cookie;");
        String[] vs = s.split(";");
        Map<String, String> m = new HashMap<>();
        for (String v : vs) {
            String[] vv = v.split("=");
            if (vv.length < 2) {
                continue;
            }
            m.put(vv[0].trim(), vv[1].trim());
        }
        return m;
    } catch (Exception e) {
        logger.debug(e.toString());
        return null;
    }
}
 
Example 4
Source File: RFXWebView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void loadScript(WebView webview) {
    webview.getProperties().put("current_selector", "body");
    WebEngine webEngine = webview.getEngine();
    JSObject win = (JSObject) webEngine.executeScript("window");
    win.setMember("marathon_recorder", RFXWebView.this);
    webEngine.executeScript(script);
}
 
Example 5
Source File: Java2JavascriptUtils.java    From javafxwebview with Apache License 2.0 5 votes vote down vote up
private static void connectToWebEngine(WebEngine engine, String varname) {
	if (	backendObjects.containsKey(engine) &&
			backendObjects.get(engine).containsKey(varname)) {
		
		JSObject window = (JSObject) engine.executeScript("window");
		window.setMember(varname, backendObjects.get(engine).get(varname));
	}
}
 
Example 6
Source File: BrowserJavascript.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void registerFunction(String functionName, WebEngine engine) {
    engine.executeScript(
        "var fun = " + functionName + " ;"
        + functionName + " = function() {"
        + "    app.functionCalled('" + functionName + "');"
        + "    fun.apply(this, arguments)"
        + "}"
    );
}
 
Example 7
Source File: O365InteractiveJSLogger.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public static void register(WebEngine webEngine) {

        try {
            Class jsObjectClass = Class.forName("netscape.javascript.JSObject");
            Method setMemberMethod = jsObjectClass.getDeclaredMethod("setMember", String.class,Object.class);

            JSObject window = (JSObject) webEngine.executeScript("window");
            setMemberMethod.invoke(window, "davmail", new O365InteractiveJSLogger());

            webEngine.executeScript("console.log = function(message) { davmail.log(message); }");
        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            LOGGER.info("netscape.javascript.JSObject not available");
        }

    }
 
Example 8
Source File: LocationTools.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static void addMarkerInGaoDeMap(WebEngine webEngine,
        double longitude, double latitude, String label, String info,
        String image, boolean multiple, int mapSize, int markSize, int textSize) {
    String jsLabel = (label == null || label.trim().isBlank()
            ? "null" : "'" + label.replaceAll("'", CommonValues.MyBoxSeparator) + "'");
    String jsInfo = (info == null || info.trim().isBlank()
            ? "null" : "'" + info.replaceAll("'", CommonValues.MyBoxSeparator) + "'");
    String jsImage = (image == null || image.trim().isBlank()
            ? "null" : "'" + StringTools.replaceAll(image, "\\", "/") + "'");
    webEngine.executeScript("addMarker("
            + longitude + "," + latitude
            + ", " + jsLabel + ", " + jsInfo + ", " + jsImage
            + ", " + multiple + ", " + mapSize + ", " + markSize + ", " + textSize + ");");
}
 
Example 9
Source File: ChatShowPane.java    From oim-fx with MIT License 5 votes vote down vote up
private void initWeb(WebEngine webEngine) {
	JSObject window = (JSObject) webEngine.executeScript("window");
	// JSObject window = (JSObject) webEngine.executeScript("document");
	if (isLoad && null != member) {
		window.setMember("oim", member);
	}
}
 
Example 10
Source File: ShowPanel.java    From oim-fx with MIT License 5 votes vote down vote up
private void initWeb(WebEngine webEngine) {
	JSObject window = (JSObject) webEngine.executeScript("window");
	// JSObject window = (JSObject) webEngine.executeScript("document");
	if(isLoad&&null!=member){
		window.setMember("oim", member);
	}
}
 
Example 11
Source File: JavaFXWebViewElement.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private static void loadScript(WebView webview, WebEngine webEngine) {
    webEngine.executeScript(script);
    webview.getProperties().put("player", webEngine.executeScript("$marathon_player"));
    webview.getProperties().put("document", webEngine.executeScript("document"));
}
 
Example 12
Source File: WritePanel.java    From oim-fx with MIT License 4 votes vote down vote up
private void initWeb(WebEngine webEngine) {
	JSObject window = (JSObject) webEngine.executeScript("window");
	window.setMember("oim", new JavaApplication());
}
 
Example 13
Source File: ChatWritePane.java    From oim-fx with MIT License 4 votes vote down vote up
private void initWeb(WebEngine webEngine) {
	JSObject window = (JSObject) webEngine.executeScript("window");
	window.setMember("oim", new JavaApplication());
}
 
Example 14
Source File: BrowserJavascript.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private void addFunctionHandlerToDocument(WebEngine engine) {
    JSObject window = (JSObject) engine.executeScript("window");
    window.setMember("app", this);
}
 
Example 15
Source File: TextEditorPane.java    From logbook-kai with MIT License 4 votes vote down vote up
/**
 * エディタの内容を取得します
 * @return エディタの内容
 */
public String get() {
    WebEngine engine = this.webview.getEngine();
    JSObject window = (JSObject) engine.executeScript("window");
    return String.valueOf(window.call("get"));
}
 
Example 16
Source File: WebBrowser.java    From yfiton with Apache License 2.0 2 votes vote down vote up
/**
 * Enables Firebug Lite for debugging a webEngine.
 *
 * @param engine the webEngine for which debugging is to be enabled.
 */
private static void enableFirebug(final WebEngine engine) {
    engine.executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}");
}
 
Example 17
Source File: WebBrowser.java    From yfiton with Apache License 2.0 2 votes vote down vote up
/**
 * Enables Firebug Lite for debugging a webEngine.
 *
 * @param engine the webEngine for which debugging is to be enabled.
 */
private static void enableFirebug(final WebEngine engine) {
    engine.executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}");
}