Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用哈希标记显示文档_Java_Html_Javafx - Fatal编程技术网

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

Java 如何使用哈希标记显示文档,java,html,javafx,Java,Html,Javafx,我正在使用超链接在默认浏览器中打开HTML文件: Hyperlink link = new Hyperlink("apple"); Path path = Paths.get("C:/Users/ExampleUser/Documents/fruits.html"); link.setOnAction(evt -> { getHostServices().showDocument(path.toString()); }); 这很好用。但是,我想使用可用的ID在特定

我正在使用超链接在默认浏览器中打开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()
方法并添加锚定:

getHostServices().showDocument("file:///C:/Users/ExampleUser/Documents/fruits.html#apple");
但是您必须添加URI方案,否则该方法将打开路径

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


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

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

getHostServices().showDocument("file:///C:/Users/ExampleUser/Documents/fruits.html#apple");
但是您必须添加URI方案,否则该方法将打开路径

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


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

这实际上成功地正确加载了文件,但它不会引导我找到
。然而,在地址栏中键入“file://C:/Users/ExampleUser/Documents/fruits.html#apple”的效果与预期一样。我再次测试了它(在Ubuntu上),它在Firefox和Chrome上都对我有效。可能您必须在之前打开该站点的情况下关闭所有选项卡,或者清除浏览器缓存,因为有时滚动位置会被缓存,并且优先于锚定标记。这实际上能够正确加载文件,但不会导致我进入
。然而,在地址栏中键入“file://C:/Users/ExampleUser/Documents/fruits.html#apple”的效果与预期一样。我再次测试了它(在Ubuntu上),它在Firefox和Chrome上都对我有效。可能您必须关闭之前打开的站点的所有选项卡,或者清除浏览器缓存,因为有时滚动位置会被缓存,并且优先于锚定标记。