当前位置: 首页>>代码示例>>Java>>正文


Java WebEngine.setJavaScriptEnabled方法代码示例

本文整理汇总了Java中javafx.scene.web.WebEngine.setJavaScriptEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java WebEngine.setJavaScriptEnabled方法的具体用法?Java WebEngine.setJavaScriptEnabled怎么用?Java WebEngine.setJavaScriptEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.scene.web.WebEngine的用法示例。


在下文中一共展示了WebEngine.setJavaScriptEnabled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: showOnlineGame

import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public void showOnlineGame(GameOnline game) {
	WebEngine webEngine = webView.getEngine();
	webEngine.setJavaScriptEnabled(true);
	
	URI uri = URI.create(MainApp.webConnector.getUrlFromGame(game));
	
	List<String> cookies = new ArrayList<>();
	for(Cookie cookie : MainApp.webConnector.cookies.getCookies()) {
		cookies.add(cookie.getName() + "=" + cookie.getValue());
	}
	
	Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>();
	headers.put("Set-Cookie", cookies);
	try {
		CookieHandler.getDefault().put(uri, headers);
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	webEngine.load(uri.toString());
}
 
开发者ID:Turnierserver,项目名称:Turnierserver,代码行数:22,代码来源:ControllerGameManagement.java

示例3: createWebView

import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public static WebEngine createWebView(FXCanvas canvas) {
	canvas.setLayout(new FillLayout());
	WebView view = new WebView();
	// When the WebEngine is initialized a CookieHandler is set, which has
	// errors reading multi value cookies, therefore set to null again
	CookieHandler.setDefault(null);
	Scene scene = new Scene(view);
	canvas.setScene(scene);
	WebEngine webkit = view.getEngine();
	webkit.setJavaScriptEnabled(true);
	webkit.setOnAlert(e -> {
		Logger log = LoggerFactory.getLogger(UI.class);
		log.error("JavaScript alert: {}", e.getData());
	});
	return webkit;
}
 
开发者ID:GreenDelta,项目名称:olca-app,代码行数:17,代码来源:UI.java

示例4: GoogleLoginDialog

import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public GoogleLoginDialog(LoginDialog parent) {
       super();
	this.setTitle(Configuration.getBundle().getString("ui.dialog.auth.google.title"));

       final WebView browser = new WebView();
       final WebEngine webEngine = browser.getEngine();

       ScrollPane scrollPane = new ScrollPane();
       scrollPane.setContent(browser);
       CookieManager manager = new CookieManager();
       CookieHandler.setDefault(manager);
       webEngine.setJavaScriptEnabled(false);

       this.getDialogPane().setContent(scrollPane);
       this.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL);

       webEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
           if(newState == State.RUNNING) {
               if(webEngine.getLocation().contains("accounts.google.com/ServiceLoginAuth")) {
                   scrollPane.setVisible(false);
               }
           }
           if(newState == State.SUCCEEDED) {
               if("https://zestedesavoir.com/".equals(webEngine.getLocation())) {
                   Element elementary = webEngine.getDocument().getDocumentElement();
                   Element logbox = getLogBox(elementary);
                   String pseudo = getPseudo(logbox);
                   String id = getId(logbox);
                   MainApp.getZdsutils().authToGoogle(manager.getCookieStore().getCookies(), pseudo, id);
                   getThis().close();
                   parent.close();
               } else {
                   if(webEngine.getLocation().contains("accounts.google.com/ServiceLoginAuth")) {
                       scrollPane.setVisible(true);
                   }
               }
           }
       });
       webEngine.load("https://zestedesavoir.com/login/google-oauth2/");
}
 
开发者ID:firm1,项目名称:zest-writer,代码行数:41,代码来源:GoogleLoginDialog.java

示例5: AuthenticationWindow

import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public AuthenticationWindow(Stage owner, Callback<AccessTokenEN, Void> callback) {
        initOwner(owner);
        initStyle(StageStyle.UTILITY);
        initModality(Modality.APPLICATION_MODAL);
        centerOnScreen();
        
        final VBox vbox = new VBox(2);
        final Scene scene = new Scene(vbox);
        setScene(scene);
        
//        setMaximized(true);
        double dW = 850;
        double dH = 650;
        Rectangle2D screen = Screen.getPrimary().getVisualBounds();
        double fW = screen.getWidth();
        double fH = screen.getHeight();
        setWidth(fW < dW ? fW * 0.8 : dW);
        setHeight(fH < dH ? fH * 0.8 : dH);

//        final TextField addressField = new TextField();
//        addressField.setEditable(false);
        
        final WebView webView = new WebView();
        webView.prefWidthProperty().bind(widthProperty());
        webView.prefHeightProperty().bind(heightProperty());
        webView.setContextMenuEnabled(true);
        webView.setCache(true);
        
        vbox.getChildren().addAll(/*addressField, */webView);

        String requestUrl = "https://api.imgur.com/oauth2/authorize?client_id={0}&response_type={1}&state={2}";
        requestUrl = requestUrl.replace("{0}", ImgurClient.CLIENT_ID);
        requestUrl = requestUrl.replace("{1}", "token");
        requestUrl = requestUrl.replace("{2}", "desktop_auth");
        final WebEngine webEngine = webView.getEngine();
        webEngine.setJavaScriptEnabled(true);
//        addressField.textProperty().bind(webEngine.locationProperty());
        
        webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends State> observableValue, State state, State newState) -> {
            if (newState.equals(State.SUCCEEDED) && webEngine.getLocation().contains("thesimego.com")) {
                Map<String, String> params = Functions.splitQuery(webEngine.getLocation());
                JSONSerializer serializer = new JSONSerializer().transform(new MapTransformer(), AccessTokenEN.class);
                String json = serializer.serialize(params);
//                System.out.println(webEngine.getLocation());
                System.out.println(json);
                JSONDeserializer<AccessTokenEN> deserializer = new JSONDeserializer<>();
                AccessTokenEN accessToken = deserializer.deserialize(json, AccessTokenEN.class);
                callback.call(accessToken);
                
                // Cookie save
                Functions.saveCookies();
                
                close();
            } 
        });
        webEngine.load(requestUrl);
        webView.requestFocus();
    }
 
开发者ID:Simego,项目名称:FXImgurUploader,代码行数:59,代码来源:AuthenticationWindow.java


注:本文中的javafx.scene.web.WebEngine.setJavaScriptEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。