Forum General

How to set BaseUrl from WKWebview to reference local file like image, css, javascript file in html

KritsadaDechawantanaKritsadaDechawantana USMember
edited November 2018 in General

Description

i can't use local image reference in html with WKWebview

Steps to Reproduce

  1. set up webview source in code behide
var source = new HtmlWebViewSource()
            {
                Html = [email protected]"
<html>
  <head>
    <title>Xamarin Forms</title>
  </head>
  <body>
    <h1>Xamrin.Forms</h1>
    <p>This is an iOS web page.</p>
    <img src=""ob03.png"" />
  </body>
</html>
                "
            };

source.BaseUrl = DependencyService.Get<IBaseUrl>().Get(); // this operation return path of directory contained image files "/var/mobile/Containers/Data/Application/BBD4FB76-852B-4BC8-BACF-A1DEAFE31C1F/Documents/mcontent/images/"
webview.Source = source;
  • webview don't display image but i change BaseUrl to bundle resouce webview display image normally

Expected Behavior

i need to display local images from local path like this "/var/mobile/Containers/Data/Application/BBD4FB76-852B-4BC8-BACF-A1DEAFE31C1F/Documents/mcontent/images/"

Tagged:
Sign In or Register to comment.