First of all, everybody happy holidays !
I have a question for when you all will go back to your PC … not drunk!
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 >
Thoughts:
I suspect that to display an image, you don’t need the File:/// at all.
Start with "C:/Users… instead
Otherwise,
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.
For example, every sample on this page omits file:// prefix…
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
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.
This is what I ended up with:
dim fTemp as FolderItem
#if XojoVersion > 2019.02 then
fTemp = FolderItem.TemporaryFile
if fTemp.Exists then fTemp.Remove()
if not fTemp.Exists then fTemp.CreateFolder()
#else
fTemp = GetTemporaryFolderItem
if fTemp.Exists then fTemp.Delete()
if not fTemp.Exists then fTemp.CreateAsFolder()
#endif
fTemp = fTemp.Child( "myHTMLViewerFile.html" )
if not fTemp.Exists then
dim t as TextOutputStream = TextOutputStream.Create( fTemp )
t.Close
t = nil
end…
DerkJ
(DerkJ)
December 26, 2020, 3:59pm
6
Perhaps its easier just to set a temp file to the second argument so the internal paths can be stored there.
https://documentation.xojo.com/api/deprecated/htmlviewer.html#htmlviewer-loadpage
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.