How to load a local help file using HTMLViewer and LoadUrl

I want to have an html page load to an anchor in that page. I can load it on a PC but the code of course doesn’t transfer.

The page with the anchor is store in a listbox in the rowtag next to the viewer.

Var str As String = IniHerd.HelpFolder.URLPath + me.RowTagAt(row)
HelpWindow.HTMLVwr.LoadURL(str)

Would someone please tell me how to write this for MacOS

At first glance, this should work on Mac.

Unfortunately it doesn’t. Not even one without an anchor.
Elsewhere I’ve noticed it has something to do with the
“file:///” and it has to be replaced.

It states that in the LR but I don’t have a replacement for a local file.

I think the ‘.URLPath’ doesn’t include the folder delimiter on the end, so you may need to detect for that.

Thanks. It’s there. Grumble.

BTW. It doesn’t work, if it doesn’t change the page.

it seems LoadUrl wants to have http or https prefix to the url.
don’t know if it accepts file:// ?
I would use the LoadPage method, if the file is on the computer ?

I can do that but (excuse sarcasm) I so wanted the anchor to work.
I also have tried changing file out for http but that wouldn’t work also.
sigh

The anchor is part of the url isn’t it? So that should not matter with the LoadPage method.

LoadPage("anchor_example2.html#a001") 

should jump to the a001 ID for instance, something like the in that html page:

<li id="a001">text here</li>

Apologies. It was a space on the end of the file name that did me in. I split the text file that I had built but it didn’t remove an extra carriage return. It doesn’t even show as an extra space on an editor.

I couldn’t figure out why I couldn’t create a folderitem for the longest.

I can now LoadURL without http.

1 Like

We had a similar case a few weeks ago, those are nasty bugs. What might help you in future is looking at the variable in the binary view to find such extra characters.

That’s how I found it.
Me What is that? Why do have a “.” on the end?

I thought Mac’s TextEdit would show little things like that.

I opened it in TextWrangler and it showed I still Windows returns. Ugh.

Lesson learned.

1 Like

Obviously, anchors do not seem to work in Mac HTMLViewer.

Here is a workaround, which displays the content from the anchor (here, “#example”):

Dim f As folderitem = SpecialFolder.UserHome.child("Downloads").child("anchor.html")
Dim PageContent As String

If f.exists Then 
  If f <> Nil Then
    If f.Exists Then
      // Be aware that TextInputStream.Open could raise an exception
      Var t As TextInputStream
      Try
        t = TextInputStream.Open(f)
        t.Encoding = Encodings.UTF8
        PageContent = t.ReadAll
      Catch e As IOException
        MessageBox("Error accessing file.")
      End Try
      t.Close
    End If
  End If
  
  Dim PageCuts() As String = PageContent.Split("<a href=""#example"">")
  
  HTMLViewer1.LoadPage("<html><body>" + PageCuts(1), FolderItem.TemporaryFile)
  
Else
  MsgBox "merde"
End If

I like the messagebox on the end. Thanks

2 Likes

:smiley: :smiley: :smiley:

1 Like