Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can't open an HTML on a specific fragment in QT using hash



  • I tried this:

    QDesktopServices::openUrl(QUrl("file:///" + QCoreApplication::applicationDirPath() + "/HELP.html#pers"));
    

    this:

    QUrl url = QCoreApplication::applicationDirPath() + "/HELP.html";
    url = QUrl::fromLocalFile(url.toString());
    url.setFragment("pers");
    QDesktopServices::openUrl(url);
    

    and with just full path, like in browser's search bar:

    QDesktopServices::openUrl(QUrl("file:///D:/ucheba/GPO/build-ReeGO-Desktop_Qt_5_13_2_MinGW_32_bit-Release/release/HELP.html#pers"));
    

    in these cases HTML opens, but just in the beginning of the document, ignoring hash (#).

    Id is correct - when i use it for linking in browser, #pers appears in a browser's search bar and HTML opens in correct place.



  • Hello, are you running in Windows?
    If yes, that's not Qt's fault to blame. Qt pass the whole url to ShellExecute Api.
    But as discussed in this stackoverflow post:

    when processing File:/// based URLs in ShellExecute(), the ShellExecute() call will strip off the # and any data it finds after the # before launching the default browser and sending in the HTML page to open. MS's stance is that they do this deliberately to prevent injections into the function.



  • Hello, are you running in Windows?
    If yes, that's not Qt's fault to blame. Qt pass the whole url to ShellExecute Api.
    But as discussed in this stackoverflow post:

    when processing File:/// based URLs in ShellExecute(), the ShellExecute() call will strip off the # and any data it finds after the # before launching the default browser and sending in the HTML page to open. MS's stance is that they do this deliberately to prevent injections into the function.



  • @Bonnie yes, i'm on Windows, thanks for the explaining!