Odd behaviour of DesktopHTMLViewer

Today I have to display, in an HTMLViewer, some HTML which contains such as:

<a href=“#downthere”>Go down there.</a>

(lots of HTML here)

<a name=“downthere”><h2>Down here</a>

This in an internal link within the document, such that when you click on it the browser scrolls you down to the linked place (as we see used a lot in the Xojo docs).

Now, I only rarely receive such HTML and was a bit surprised today to see that, when I display this in my app, these links don’t work. On looking intio the matter, I soon found that I cannot reproduce this in a small example. With HTML, I can either read it out of a database into a string, and do:

myViewer.LoadPage (htmlstring, Nil)

or have the string in a file and use:

myViewer.LoadPage (afolderitem)

to display it. With a small example, both methods work, but in my app the first method works and the second doesn’t and I can’t see why.

This is macOS with 2023r4.1 - any suggestions?

That should read:

<a href=“#downthere”>Go down there.</a>

(lots of HTML here)

<h2 id=“downthere”>Down here</h2>

Modern HTML uses the id to represent the destination. That certainly works for HTML5. What is the doctype on your page?

It’s <!doctype html>.

And while I agree with you, I am forced to deal with the html as it is supplied to me. I already go through and check for and alter a number of things in html I receive. In any case, when I tried your suggested change by hand, it made no difference; clicking on the links had no effect.

Given that my simple example project works (i.e., the links when clicked work as expected), while my preferred way of doing it (which was one of the two ways that work in the example project) does not work in my app (i.e., the same html, when the links are clicked it has no effect), I am reduced to thinking that my DesktopHTMLViewer is in some state or other which precludes such links from working. At this point I am at a loss to think of what I might have done to it.

Hmm… that is HTML5. It’s not smart quotes is it? perhaps the browser isn’t recognising the duff quotes?

It’s also worth extracting the HTML form the HTMLViewer and then pasting that into Safari and pressing command-shift-U to view the console. See if anything looks wrong?

1 Like

No. The quote comes in as &h22. Further, in my example project, I’m using HTML that I created myself in BBEdit (and I use the <a name=… formulation since that was what was in the original HTML). Double-clicked on the desktop as an .html file, it opens in Safari and behaves properly. If I finagle that HTML into my app, it doesn’t work; clicking on the link is ignored.

Further, changing to use id=… has no impact on either how my app behaves or my example project behaves.

I did also find this:

which my app already does for its Windows incarnation. Perhaps I’ll just have to bite the bullet and do that for macOS/Linux too. Coding for the HTMLViewer appears to be a moving target.

I - sometimes - generate html files, but I do not use that:

<h2 id=“downthere”>Down here</h2>

I use [instructions to load an image and display a comment]

without troubles (MacOS).

Correction: the first method doesn’t work and the second one does.