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.
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:
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.
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
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 & has a value./dt
Imagine there’s chevron round the dt to the end of ‘m050’ and /dt.