本文整理匯總了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));
}