HTML Hyperlinks within document?

  • I'd like to provide a way to have a TOC in an HTML output that hyperlinks to another location within the document. For example, in HTML you can have a hyperlink use href="#some_id" which locates something that has the attribute of id="some_id", such as a SPAN element.

    Is there a way to do this? I already add bookmarks for this when creating a TOC for PDFs as well as user bookmarks, and it would be cool if you could automatically convert them to the above when outputting as HTML. But I am fine with having to do it in code but I just don't know how to do that and if it is even possible.

    Right now for HTML output the TOC hyperlinks create the href but without the # prefix, so it attempts to open an external page, and bookmarks don't even get output, but would be nice if they get output as a span using the bookmark name as the ID.

    Thoughts?

  • Well, yeah, I do that and could prefix it with a # when outputting to HTML instead of RTF for PDF creation, but where is the hyperlink going to go? How do I set the ID on the destination element? It would be nice if bookmarks automatically converted to say a SPAN element with the ID equal to the bookmark name, and likewise automatically prefixed the hyperlink source with the # (but I can do that latter part easily).

    So basically, what can I use instead of a bookmark when outputting to HTML to be able to set the destination element's ID? Seems the bookmarks are not output in any form when creating HTML.

  • Doh! Nevermind, you don't have to change anything. My bad. I'm doing too many things at once!

    Just before outputting to HTML I was apparently calling BookmarkDeleteAllMarkers (old code), which is why I didn't see any bookmarks in the HTML output.

    Once that was corrected, the bookmarks (which change to anchor tags in HTML output) are perfectly fine with just the name, no need for an additional ID attribute. All I had to do was add a # prefix to any of my hyperlinks that reference an internal bookmark, such as in the TOC creation. All good.

    Sorry.

    Einmal editiert, zuletzt von ehimmer (25. August 2021 um 19:21)

  • Interesting note for RTF based hyperlinking within the document. Bookmark names have to start with a letter for it to work when loading that RTF into Word. I was starting my bookmark names with an underscore like: _TOC_blahBlahBlah

    This did not work when loading into Word. I had to remove the leading underline.