本文整理汇总了Java中javafx.scene.web.WebEngine.setUserAgent方法的典型用法代码示例。如果您正苦于以下问题:Java WebEngine.setUserAgent方法的具体用法?Java WebEngine.setUserAgent怎么用?Java WebEngine.setUserAgent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.web.WebEngine
的用法示例。
在下文中一共展示了WebEngine.setUserAgent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public final void initialize(Stage s) {
this.stage = s;
WebEngine engine = this.webBrowser.getEngine();
String userAgent = engine.getUserAgent();
engine.setUserAgent(userAgent.substring(0, userAgent.indexOf(')')) + "; rv:56.0) Gecko/20100101 Firefox/56.0");
engine.setJavaScriptEnabled(true);
engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.equals(State.SUCCEEDED)) {
String location = engine.getLocation();
if (!location.contains("sh.st") && !location.contains("adf.ly") && !location.contains("krothium.com") && !location.contains("about:blank")) {
this.webBrowser.getEngine().load("about:blank");
}
if (location.contains("about:blank") && !this.toHide.isShowing()) {
this.toHide.show();
s.close();
}
}
});
}
示例2: createDocument
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public Document createDocument(JavaScriptEngine engine) {
DocumentImpl documentImpl = (DocumentImpl) ((WebKitJavaScriptEngine) engine).getEngine().getDocument();
WebEngine webEngine = (WebEngine) engine.getEngine();
if (configuration.getUserAgent() != null) {
webEngine.setUserAgent(configuration.getUserAgent());
}
webEngine.getLoadWorker().exceptionProperty().addListener(new ExceptionListener(log));
webEngine.setOnError(new DefaultErrorEventHandler());
Document document = new WebKitDocument(this, documentImpl, (WebKitJavaScriptEngine) engine);
selector = initializeSelectorEngine(document, (WebKitJavaScriptEngine) engine);
return document;
}
示例3: setUserAgent
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public static void setUserAgent(WebEngine e) {
if (!e.getUserAgent().contains("ZunoZap")) e.setUserAgent(e.getUserAgent() + " ZunoZap/" + version + " Chrome/60.0.3112");
else System.err.println("Useragent has already been set!");
}
示例4: start
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
@Override
public void start(final Stage stage) throws Exception {
// required to allow CORS
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
BorderPane borderPane = new BorderPane();
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.setUserAgent("Yfiton");
Map<String, String> parameters = getParameters().getNamed();
borderPane.setCenter(browser);
webEngine.documentProperty().addListener((prop, oldDoc, newDoc) -> {
String debugMode = parameters.get("debug");
if (debugMode != null && debugMode.equalsIgnoreCase("true")) {
enableFirebug(webEngine);
}
});
webEngine.load(parameters.get("authorization-url"));
Class<?> listenerClass = Class.forName(parameters.get("webengine-listener-class"));
WebEngineListener listener =
(WebEngineListener) listenerClass.getConstructor(
WebEngine.class, String.class, String.class).newInstance(
webEngine, parameters.get("authorization-file"), parameters.get("authorization-code-parameter-name"));
webEngine.getLoadWorker().stateProperty().addListener(listener);
stage.setTitle("Yfiton");
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
scene =
new Scene(
borderPane,
primaryScreenBounds.getWidth() * 0.55,
primaryScreenBounds.getHeight() * 0.65);
stage.setScene(scene);
stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/yfiton-icon.png")));
stage.show();
stage.setOnCloseRequest(event -> System.exit(EXIT_CODE_ON_CLOSE));
}