How to display images in WKWebViewControlMBS?

  1. 4 months ago

    Grzegorz P

    Jul 9 Pre-Release Testers Europe (Poland, Warszawa)

    How can I display images in WKWebViewControlMBS when opening an HTML page from a string (using WKWebViewControlMBS.LoadHTML)?

    In the build-in HTMLViewer I can use LoadHTMLStringMBS and the following HTML code:

    <img src='file:///Users/current_user/Desktop/test.jpg' width=100 height=100>

    Unfortunately, It does not work in WKWebViewControlMBS. However, images *are* displayed when opening an actual website with WKWebViewControlMBS.LoadURL.

    How to display the image?

  2. Grzegorz P

    Jul 13 Pre-Release Testers Europe (Poland, Warszawa)

    It seems WKWebView has some additional restrictions concerning opening local files.

    So, if anyone searches this forum in the future for the same problem:

    It works, if I first use WKWebViewControlMBS.LoadURL method to open any local file. The file doesn't even need to exist! Just calling WKWebViewControlMBS.LoadURL(SpecialFolder.Resources.URLPath+"test.html") is enough to "unlock" the volume for local access from WKWebViewControlMBS. I am using a dummy html file located in my app Resources folder. After that, I can use WKWebViewControlMBS.LoadHTML(s, baseURL), where s is the string containing my html code referring to local images, and baseURL is SpecialFolder.ApplicationData.URLPath (or, in fact, a proper ApplicationData.Child() for the folder my app stores the images to be displayed). Not providing the baseURL or not using LoadURL first results in no images displayed.

    It seems to work fine, and is much, much faster (seriously, orders of magnitude faster) than the built in HTMLViewer, which is based on WebView, depreciated by Apple around 10.10 and being more and more crippled with each macOS version, as far as speed is concerned.

  3. Christian S

    Jul 13 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Maybe you need to set allowFileAccessFromFileURLs property to true to make it work?
    See WKWebViewControlMBS documentation.

  4. Grzegorz P

    Jul 17 Pre-Release Testers Europe (Poland, Warszawa)

    I know why I missed that - I am using an older version of the plugins and there is no allowFileAccessFromFileURLs property here.

or Sign Up to reply!