gpt4 book ai didi

java - 如何使用哈希标记显示文档

转载 作者:太空宇宙 更新时间:2023-11-04 09:47:41 25 4
gpt4 key购买 nike

我使用超链接在默认浏览器中打开 HTML 文件:

Hyperlink link = new Hyperlink("apple");
Path path = Paths.get("C:/Users/ExampleUser/Documents/fruits.html");
link.setOnAction(evt -> {
getHostServices().showDocument(path.toString());
});

效果很好。但是,我想使用可用 ID 在特定点打开文档,并立即跳转到“C:/Users/ExampleUser/Documents/fruits.html#apple”。这可能吗?

最佳答案

您可以直接调用 showDocument() 方法并添加 anchor :

getHostServices().showDocument("file:///C:/Users/ExampleUser/Documents/fruits.html#apple");

但是你必须添加URI方案,否则该方法将打开路径

file://C:/Users/ExampleUser/Documents/fruits.html%23apple

这显然不是您要打开的 URI。

关于java - 如何使用哈希标记显示文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55211884/

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