iOS Question b4i location css file in html file

joop

Active Member
Licensed User
Longtime User
Hi, in B4a the css location in a html file is
<link rel= "stylesheet" type ="text/css" media= "screen" href = "file:///android_asset/style.css"/>

the "file:///android_asset/style.css" must be replaced by something in b4i ,anyone figured this out ?

I tried
file://style.css
file://asset/style.css
file://b4i/asset/style.css

I tried
<link rel= "stylesheet" type ="text/css" media= "screen" href = "style.css"/>
wich also didn't work.
 
Last edited:

JanPRO

Well-Known Member
Licensed User
Longtime User
Check this out:
B4X:
    Dim CSSPath As String = File.Combine(File.DirAssets,"style.css")
    Dim HTML As String = $"<link rel= "stylesheet" Type ="text/css" media= "screen" href = "${CSSPath}"/>"$
   
    WebView1.LoadHtml(HTML)
 
Upvote 0

joop

Active Member
Licensed User
Longtime User
Hi Jan thanks for your answer, I tried this:

files are located in Appname\files directory
files used test.html style.css


file =test.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

<link rel= "stylesheet" type ="text/css" media= "screen" href = "style.css"/>

<title>Test</title>
<meta content="joop" name="author">
<meta content="test" name="description">
</head>

to load the style file I did your code :

B4X:
Dim CSSPath As String = File.Combine(File.DirAssets,"style.css")
Dim html As String = $"<link rel= "stylesheet" Type ="text/css" media= "screen" href = "${CSSPath}"/>"$
WebView1.LoadHtml(html)

to load the html file I did:

B4X:
html = File.ReadString(File.DirAssets, "test.html")
WebView1.LoadHtml(html)

The webpage is shown in debug and release app but without the css styling.

How can Webview1 remember the location off the css file when parsing the
html file ?, I think I don't understand it fully.

Joop


 
Upvote 0

joop

Active Member
Licensed User
Longtime User
Hey Jan It works! Suddenly I understood what you meant .
I added the ccs html with the test.html ,thanks!
 
Upvote 0

joop

Active Member
Licensed User
Longtime User
Another thing comes up,when loading pictures etc wich location must be given
in the HTML file :

In android it was like this:

<img src="file:///android_asset/strand.jpg" alt="strand.jpg"> <br>
<input type="button" class="knop" onClick="parent.location='file:///android_asset/strandvak11025.mp3' " >
<input type="text" value="Zandvoort aan zee" readonly>
<br> <br>

but in IOS 'file://strandvak11025.mp3' " doesn't work.
It must be something different?
 
Upvote 0

joop

Active Member
Licensed User
Longtime User
Yes it works the first time, but close the app and start again , the path is changed (virtual files),so the path cannot be stored in the html files because the html files are static in the asset folder ( \files directory) ,hmm.

Why is this so different compared with other browsers or b4a , is b4i causing this ,or ios ,or objective c ? o_O
Is it not possible to get the files in the directory \files directly.?

two different locations
/private/var/mobile/Containers/Data/Application/1BA2C073-DE2F-4169-855A-004A15A8A29F/tmp/virtual_assets/manstrand.jpg
/private/var/mobile/Containers/Data/Application/D5B03108-4760-4980-A828-D14BD117F55A/tmp/virtual_assets/manstrand.jpg
 
Upvote 0
Top