当前位置: 首页>>代码示例>>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;未经允许,请勿转载。