當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。