Jump to an anchor point in DesktopHTMLViewer

Can anyone point me in the right direction please?

I have an htmlViewer which I use to display help text. Works fine. I also have a message handler. Each message is prefixed by a number: M999 - Messge text.

There’s a help page with an explanation of every possible message. I have added an anchor to each message (

M001 - My message.
)

I want to click on a message in the application and open the message explanation page and jump immediately to the message. Currently I can click the message and open the page in the viewer but I can’t get it to jump.

I do have a partial solution. I have added a link at the top of the explanation page for each message and the user can click one of those. It works but it’s one of those situations you just know there has to be a better way.

I should say my knowledge of HTML is limited to authoring help text and my knowledge of JavaScript (which the internet says may offer a solution) is non existent. If JavaScript is an answer I need to get the script the message prefix (the M999 bit) and I’ve no idea how to do that.

Can anyone advise, please.

Jack

Sorry, that didn’t come out as I intended. The anchor point should have read

´

M001 - My Message.

How you you include HTML in these post?

You define a named anchor with # and then you add a link to the anchor by adding #anchor name to the link. For instance I made some anchors for troubleshooting in the manual of my app so that I can send users links to the specific section:


https://manual.mothsoftware.com/userreference/troubleshooting/troubleshooting.html#database-corruption

The htmlviewer should work the same.

You can get an eye at:

Base Web Site and go bottom for the list of languages or:

HTML Language

They also have SQL, etc.

You already have one part (the click part) and you must add a:

so the click part code know where to go.

Example:

Link to click:
<a href="#Mag_01">Année Zéro 01</a><br>

Location the link will go to:
<a name="Mag_01"></a><font size=5>Année Zéro 01</font><br>

In this example, the first line is in a ToC table,
the second line is after the ToC table, in the Issue 1 of the Book (named “Année Zéro 01”).

This is pure html code you put in your help file. Check the previous answer to know how to tell HTMLViewer to load the needed file.

You now have the information (web site) to create your Help full html files.

HTH

Thanks Beatrix

I know how to code the anchor and as a user I know how to use them in HTML but I want to follow the link programmatically. I don’t want to depend on having the link in the HTML document and having to click on it.

Not sure you’ve got what I’m tying to do here.

I know how the links work and I’ve got them. Every message is coded with an HTML id to make it an anchor

<dd id="m001" (with a close chevron followed by the message) M001 - Message text. and a then a close /dd

(If I try to show the HTML in here it displays it as plain text which is what happened in my 2 and 3 posts above).

What I want to do, when the page loads and a message number is available skip immediately to the anchor without any user intervention. I need to get that message number (the M001) from my Xojo code and then use HTML or JavaScript to skip to that target and finally, ideally, get back into Xojo and clear the target message number variable. No user action required. I need to if I can get the anchor name out of Xojo and, not knowing anything about JavaScript, how do I action the skip.

The JavaScript in this post can be easily modified to achieve your desired result.

Something like this (untested browser code):

Public Function ScrollToID(extends viewer as DesktopHTMLViewer, id as String)
  viewer.ExecuteJavaScript("document.getElementById('" + id + "').scrollIntoView(true);")
End Function
var helpPage as FolderItem
var vars(0) as String
var msgNo as String = "m050"

// Call the help system if the text is a msg .
if me.Text.Left(1) = "M" _
    and IsNumeric(me.Text.Middle(1, 3)) _
    and me.Text.Middle(4, 3) = " - " then

    helpOpened = True
    helpPage = appHelp.helpFolder.Child("messages.html")
    appHelp.run(helpPage)
    if errorCode <> 0 then
        vars(0) = str(errorCode)
        msgText.Text = getMessage(10, vars)
    end if
    for i as Integer = 0 to app.LastWindowIndex
        if app.WindowAt(i) isa helpBrowser then
            var w as helpBrowser = helpBrowser(app.WindowAt(i))
            if msgNo <> "" then _
            w.helpViewer.ExecuteJavaScript("document.getElementById('" + msgNo +           "').scrollIntoView(true);")
            exit
        end if
    next
end if

#Pragma Unused x
#Pragma Unused y

Sorry I can't get it to work. As I said, I know nothing about JavaScript. The code above runs in the call to my help system to open the messages page. It checks if a message is currently being displayed. If one is then it gets a reference to the help window and calls ExecutreJavaScript.
Once If get this working it will be tidied up, I just need to get it working.

Help, please.
Jack

The javascript looks correct, but your anchors need to be defined correctly as id’s in the HTML.

See this sample project.
HTMLViewer_Scroll.zip (6.0 KB)

Yes, I’ve fallen for that before.

Below is a sample anchor. My unsatisfactory workaround at the moment is to put a link at the top of the message page for every message and they all function correctly.

M050 - '&' cannot be zero if '&' has a value.

I can’t get the form editor to display HTML

dt id=“m050” M050 - & cannot be zero if &amp has a value./dt

Imagine there’s chevron round the dt to the end of ‘m050’ and /dt.

Hi John,

I’m trying to be creative, below…

Why not creating on the fly the Help file and associated data in the Temporary folder (delete it on exit) your help file (as html) ?

Create a db file with all needed data (eventually), add Help title, Help text and Help Image(s).in another TABLE who have the same Help Title…

Look nice, but I do not have data to know if this is OK or to be avoided because it is hard to implement…