gpt4 book ai didi

java - 如何在 javafx 浏览器中操作链接

转载 作者:行者123 更新时间:2023-11-30 11:34:10 24 4
gpt4 key购买 nike

        //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 中的“广告程序”时,它应该转到 (propams.com) 以及我点击过的网址

感谢您提前帮助我。

最佳答案

在你的代码中,你应该首先尝试理解历史是如何在浏览器中显示的,如果你弄清楚了,那么我想你只需要编写一个简单的 if else 逻辑来操作链接到你想要的任何地方所以首先尝试显示历史我想这应该可以解决问题

关于java - 如何在 javafx 浏览器中操作链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15794516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com