I'm trying to make my JAVA software opens its documentation file (.html) when an user click on a button, but at a specific anchor depending on the button clicked, for a better guidance for the users.
For that, I have in the documentation file a tags, for example
<a name="Computations">
Here's a snippet of what I'm trying to achieve:
public static void displayHelp(String HelpID){
StringBuilder sb = new StringBuilder();
sb.append("file:///");
sb.append("C:/.../userManual.html");
sb.append("#");//or \u0023
sb.append(HelpID);
try {
URI uri = new URI(sb.toString());
Desktop.getDesktop().browse(uri);
} catch (IOException | URISyntaxException e1) {
e1.printStackTrace();
}
}
public static void main(String[] args) {
displayHelp("Computations");
}
Launching this snippet will open the default browser, as intended, but at the beginning of the documentation file, which is strange since that if you take the same StringBuilder content (file:///C:/.../userManual.html#Computations) and search it in the default browser, it opens the documentation file at the specified anchor.
Further investigation on the URI class shows the constructor is parsing the String I give him, and consider the part after the # (Computations) as its fragment, hence not displaying this part on the research bar when launching the main.
Did I miss something on the URI class, which would allow me to do what I'm intending ?
If not, is there a workaround to this, which does not include JavaHelp, since I need to do a search in my file ?