HTMLViewer: Xojo + JavaScript Communication

Are you loading an html file or loading an html string by code? If loading an html string, don’t forget to set the RelativeTo parameter to the correct base folder.

I’m doing:

myViewer.LoadPage (htmlbody, f)

with htmlbody containing the html string, and f being a folderitem for the folder containing images. Inside the html there will be such as:

<img src="file:///path/to/folder/someimage.jpg">

Edit: sorry, incomplete URL.

Probably you need to use relative images, instead of absolute paths.

Works OK under macOS, also if I use native renderer under Win7/10.

As far as I know, you needed to trick the OS to make it work in MacOS relaxing the access using Sam’s Declares and functions.

That is correct, yes.

No need we use the defaults functions of xojo without issues.

2020r1?

1 Like

It worked without Sam’s Declares until 2020r1.

Yes, or older engines were more relaxed, or Xojo did not compile a more relaxed version of CEF.

1 Like

https://documentation.xojo.com/api/deprecated/htmlviewer.html#htmlviewer-loadpage

RelativeTo is a file…

1 Like

I think Derk found your problem. I missed your error. :smiley:

1 Like

Wrong, it should not be a folder but a file.

Try https://documentation.xojo.com/api/files/folderitem.html.TemporaryFile

Copy the files (images etc) in the parent folder if this folderitem and relativeto to this file

It should just work

Not necessary. Just point f to any file where the images are.

1 Like

Yes that can be done also. But it must be a folderitem (file) as far as i know. All other files should be relative to it and be readable.

edit:

HTMLViewer.LoadPage(File as FolderItem) 

can also be used, must be a file. Other files will be relative.

I have folders, htmls and images in the resources folder of one app. I just point it to there. Once the app is installed, all files are set in place.

1 Like

Instead of LoadPage, if you used LoadURL, images would naturally show no matter the renderer, if you make sure they are present next to the page, or in a subfolder. That is what I do in my apps. I simply use a file copy step to put all the files into Resources.

dim f as folderitem = TPSF.Resources.child("page.html")
'with 2019R3.2 or more recent, you can do specialfolder.Resource.child("page.html")
WebViewer.LoadURL(f.URLPath)

That works, just like in Xojo iOS this works.

It should work until recently, but now the manual includes some uncertainty that make us feel unsafe:

HTMLViewer.LoadURL (URL as String)

Loads the passed HTTP URL. Any protocol other than HTTP may or may not work as that is dependent on operating system behavior.

So

HTMLViewer.LoadPage (File as FolderItem)

Seems the way to go.

1 Like