當前位置: 首頁>>代碼示例>>Java>>正文


Java WebEngine.setUserAgent方法代碼示例

本文整理匯總了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();
            }
        }
    });
}
 
開發者ID:DarkLBP,項目名稱:Krothium-Launcher,代碼行數:20,代碼來源:BrowserFX.java

示例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;
}
 
開發者ID:webfolderio,項目名稱:ui4j,代碼行數:14,代碼來源:WebKitPageContext.java

示例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!");
}
 
開發者ID:ZunoZap,項目名稱:zunozap,代碼行數:5,代碼來源:ZunoAPI.java

示例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));
}
 
開發者ID:yfiton,項目名稱:yfiton,代碼行數:46,代碼來源:WebBrowser.java


注:本文中的javafx.scene.web.WebEngine.setUserAgent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。