2
        //process history
        final WebHistory history = webEngine.getHistory();

        history.getEntries().addListener(new 
            ListChangeListener<WebHistory.Entry>(){
                @Override
                public void onChanged(Change<? extends Entry> c) {
                    c.next();
                    for (Entry e : c.getRemoved()) {
                        comboBox.getItems().remove(e.getUrl());

                    }

                    for (Entry e : c.getAddedSubList()) {
                        comboBox.getItems().add(e.getUrl());
                    }
                        System.out.println(webEngine.getLocation());
                    if(webEngine.getLocation().matches("http://www.google.co.in/")){}
                    else if(webEngine.getLocation().contains("http://in.yahoo.com/")){}
                    else{

          browser.setOnMouseClicked(new EventHandler<MouseEvent>(){

          @Override
          public void handle(MouseEvent arg0) {

                String[] manipulateurl= {
                                         "http://www.gmail.com",
                                         "http://www.flipkart.com"};
                String temp=address.getText();


               if (manipulatedindex>1)
                   manipulatedindex=0;

               temp=manipulateurl[manipulatedindex];
               System.out.println(manipulateurl[manipulatedindex]+"      "+temp);
               address.setText(temp);


                webEngine.load(temp);
                manipulatedindex++;

}

    });}



//                         webEngine.getLocation()
                }
        });

        //set the behavior for the history combobox               
        comboBox.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent ev) {
                int offset =
                        comboBox.getSelectionModel().getSelectedIndex()
                        - history.getCurrentIndex();
                history.go(offset);
            }
        });



        // process page loading
        webEngine.getLoadWorker().stateProperty().addListener(
            new ChangeListener<State>() {
                @Override
                public void changed(ObservableValue<? extends State> ov,
                    State oldState, State newState) {
                    toolBar.getChildren().removeAll(showAll, hideAll);    
                    if (newState == State.SUCCEEDED) {
                            JSObject win = 
                                (JSObject) webEngine.executeScript("window");
                            win.setMember("app", new JavaApp());
                            if (needForumButtons) {
                                toolBar.getChildren().addAll(showAll, hideAll);
                            }
                        }
                    }
                }
        );

        // load the home page  
        String x="http://www.google.com";
    webEngine.load(x);
        //add components

        getChildren().add(toolBar);


        getChildren().add(browser);
    }

    // JavaScript interface object
    private class JavaApp {

        public void exit() {
            Platform.exit();
        }
    }

    private Node createSpacer() {
        Region spacer = new Region();
        HBox.setHgrow(spacer, Priority.ALWAYS);
        return spacer;
    }

    @Override
    protected void layoutChildren() {
        double w = getWidth();
        double h = getHeight();
        double tbHeight = toolBar.prefHeight(w);
        layoutInArea(browser,0,0,w,h-tbHeight,0,HPos.CENTER,VPos.CENTER);
        layoutInArea(toolBar,0,h-tbHeight,w,tbHeight,0,HPos.CENTER,VPos.CENTER);
    }

    @Override
    protected double computePrefWidth(double height) {
        return 750;
    }

    @Override
    protected double computePrefHeight(double width) {
        return 600;
    }
}

这是我的代码。有人可以帮我操作浏览器上的链接吗,例如让我说当我点击 google.com 中的“广告程序”时,它应该使用我点击的 url 转到 (propams.com)

感谢您提前帮助我。

4

1 回答 1

1

在您的代码中,您应该首先尝试了解历史记录是如何在浏览器中显示的,然后我想您只需要编写一个简单的 if else 逻辑来操作指向您想要的任何位置的链接,所以首先尝试显示历史记录我猜应该做的伎俩

于 2013-08-30T16:01:08.683 回答