HTMLViewer.LoadPage(string,Nil) not show images

First of all, everybody happy holidays !
I have a question for when you all will go back to your PC :computer: … not drunk! :clinking_glasses:

I stored the following string in memory which contains an html test.
HTMLViewer loads it, but it fails to display the image even though the url is absolute path.

Is it a problem of HTMLViewer? Or do I have to work with NIL in some way? If so, how?

sRecordReaded = "<!DOCTYPE html><html><head><meta http-equiv=""content-type"" content=""text/html; charset=UTF-8""><title></title></head><body>" _
+ "<p>Ciao</p><img src=""file:///C:/Users/Miche/AppData/Roaming/AppTest/MAP/Icon/anImmage.png"" alt=""b"" title=""a""></body></html>"

HTMLV_Map.LoadPage(sRecordReaded, Nil)

Here the html to make it more readable :

< !DOCTYPE html>
< html>
. . < head>
. . . . < meta http-equiv=“content-type” content=“text/html; charset=UTF-8”>
. . . . . . . < title>
. . < /head>
. . . . < body>
. . . . . . . . < p>Ciao< /p>
. . . . . . . . < img src=“file:///C:/Users/jocke/AppData/Roaming/FOS-FlyOnSky/MAP/Icon/WPFlightPlan.png” alt=“b” title=“a” >
. . . . < /body >
< /html >


I suspect that to display an image, you don’t need the File:/// at all.
Start with "C:/Users… instead

If you save that as a text file with an HTML extension, does the file display?
Should there be 3 slashes after File: ?

Hi Jeff.
file:/// is right.
The file: URL scheme refers to a file on the client machine.

file:/// is right.

Not 100% convinced. :slight_smile:

For example, every sample on this page omits file:// prefix…

URL scheme refers to a file on the client machine.

Your machine, or a client’s machine?

If you check locations in CancelLoad, you’ll probably see about:blank#blocked is one of them. You likely just need to supply a valid FolderItem as the second parameter of your LoadPage call.

Here’s a bit of code I posted back in September for similar issues.

Perhaps its easier just to set a temp file to the second argument so the internal paths can be stored there.

Just set RelativeTo to FolderItem.TemporaryFile and xojo creates a temp file for you

There was a reason that didn’t work, and I don’t remember why now. I had to actually create a directory and a file to get it to behave as expected, but that may be fixed since September, or may have been something for my specific usage. That’s what I came up with after trying a bunch of different things while pestering @William_Yu about how it actually functions.

UPDATE: I remember now. The RelativeTo file extension had to be .html or .htm for the new CEF security.

In practice there are no solutions unless creating the file physically:

  • create a temporary file and modify it with the extension .html (or .htm)
  • with TextOutputStream insert the html code inside the file created
  • HTMLViewer reads the file
  • we can also delete the temporary file (we work with the DOM)

It still does not work with an HTML in memory (in a string variable), the page is displayed, the text as well, but not the image.

sRecordReaded = "<!DOCTYPE html><html><head><meta http-equiv=""content-type"" content=""text/html; charset=UTF-8""><title></title></head><body>" _
+ "<label id=""lbltipAddedComment"">test</label><p>Ciao</p><img src='file:///C:/Users/jocke/Desktop/tmpImg/WPFlightPlan.png' alt=""b"" title=""a""></body></html>"

Var fileTmp As FolderItem = FolderItem.TemporaryFile
fileTmp.Name =  fileTmp.Name.ReplaceAll(".", "")
fileTmp.Name =  fileTmp.Name + ".html"
// fileTmp is an empty file !!!
HTMLV_Map.LoadPage(sRecordReaded, fileTmp)

Maybe I’ll take the first route: temporary.html file.

Thanks everyone for the support.