本文整理汇总了Java中javafx.scene.web.WebEngine.executeScript方法的典型用法代码示例。如果您正苦于以下问题:Java WebEngine.executeScript方法的具体用法?Java WebEngine.executeScript怎么用?Java WebEngine.executeScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.web.WebEngine
的用法示例。
在下文中一共展示了WebEngine.executeScript方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getListener
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
private ChangeListener<Worker.State> getListener(final DropboxManager.DropboxAccountLinkListener dropboxAccountLinkListener,
final DbxWebAuthNoRedirect webAuth, final WebEngine engine, final Stage stage) {
return (observable, oldValue, newState) -> {
if (newState == Worker.State.SUCCEEDED) {
try {
final String authCode = (String) engine.executeScript("document.getElementById('auth-code').textContent");
LOGGER.debug("Authorization Code [{}]", authCode);
DbxAuthFinish authFinish = webAuth.finish(authCode);
String accessToken = authFinish.accessToken;
final DbxAuthInfo dbxAuthInfo = new DbxAuthInfo(accessToken, DbxHost.Default);
DbxAuthInfo.Writer.writeToFile(dbxAuthInfo, accessTokenFile);
DbxClient client = new DbxClient(dropboxConfig, dbxAuthInfo.accessToken, dbxAuthInfo.host);
final String displayName = client.getAccountInfo().displayName;
LOGGER.info("Linked account [{}]", displayName);
stage.close();
dropboxAccountLinkListener.accountLinked(AccountInfoFactory.getAccountInfo(client.getAccountInfo()));
} catch (Exception e) {
// ignore
}
}
};
}
示例2: executejQuery
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
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 + "});");
}
示例3: executejQuery
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
/**
* 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 + "});"
);
}
示例4: connectToWebEngine
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
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));
}
}
示例5: changed
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
if (newValue == State.SUCCEEDED) {
WebEngine engine = getWebView().getEngine();
if (ValueUtil.isNotEmpty(initCont)) {
engine.executeScript(" document.getElementById('gargoyle-textarea').innerHTML= '" + initCont + "'; ");
}
engine.getLoadWorker().stateProperty().removeListener(this);
webViewLoaded.set(true);
}
}
示例6: start
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
WebView view = new WebView();
WebEngine engine = view.getEngine();
JSObject win = (JSObject) engine.executeScript("window");
win.setMember("scriptReady", new ScriptReady());
engine.load(getClass().getResource(EXTERNAL_PAGE).toExternalForm());
stage.setScene(new Scene(new BorderPane(view), 640, 480));
stage.show();
}
示例7: registerFunction
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
private void registerFunction(String functionName, WebEngine engine) {
engine.executeScript(
"var fun = " + functionName + " ;"
+ functionName + " = function() {"
+ " app.functionCalled('" + functionName + "');"
+ " fun.apply(this, arguments)"
+ "}"
);
}
示例8: connectToWebEngine
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
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));
}
}
示例9: setUp
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
final WebEngine webEngine = new WebEngine();
Object obj = webEngine.executeScript("({ text: 'message', number: 42, boolean: true," +
"func: function() {}, object: { foo: 'bar' }, array: [1, 3, 5] })");
assertTrue(obj instanceof JSObject);
this.jsObject = (JSObject) obj;
}
示例10: Bridge
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
Bridge(WebEngine engine){
this.engine=engine;
// engine.executeScript("$(document).ready(function() {"+
// "updateMethodName='"+update()+"'; " +
// "});");
engine.executeScript("updateMethodName='"+update()+"'; ");
}
示例11: onLoaded
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void onLoaded(WebEngine webkit) {
this.webkit = webkit;
JSObject window = (JSObject) webkit.executeScript("window");
window.setMember("java", new JsHandler());
refresh();
}
示例12: onLoaded
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void onLoaded(WebEngine webkit) {
JSObject win = (JSObject) webkit.executeScript("window");
win.setMember("java", new JsHandler());
String version = M.Version + " " + Config.VERSION + " ("
+ OS.getCurrent() + " " + getArch() + ")";
webkit.executeScript("document.getElementById('version').innerHTML = '"
+ version + "'");
}
示例13: onLoaded
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void onLoaded(WebEngine webkit) {
log.trace("page completed, set data");
UI.bindVar(webkit, "java", new JsHandler());
try {
List<CategorizedDescriptor> list = runSearch();
Gson gson = new Gson();
String json = gson.toJson(list);
String command = "setData(" + json + ")";
webkit.executeScript(command);
} catch (Exception e) {
log.trace("Failed to load data: where used", e);
}
}
示例14: onLoaded
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void onLoaded(WebEngine webkit) {
Gson gson = new Gson();
String json = gson.toJson(report);
String messages = M.asJson();
String command = "setData(" + json + ", " + messages + ")";
try {
webkit.executeScript(command);
} catch (Exception e) {
log.error("failed to set report data to browser", e);
}
}
示例15: onLoaded
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void onLoaded(WebEngine webkit) {
UI.bindVar(webkit, "java", new Js());
Gson gson = new Gson();
for (Comment comment : comments.getForPath(path)) {
webkit.executeScript("add(" + gson.toJson(comment) + ", true);");
}
}