iOS Question Clear WebView Cache

cbanks

Active Member
Licensed User
Longtime User
How do I clear the WebView cache? I may need to do this after making a change to the css file because the web pages are not taking the new css change.
 

cbanks

Active Member
Licensed User
Longtime User
The clear cache code doesn't make the css change appear.

How do I go about appending that dummy string to yourcss.css because the reference to yourcss.css is in each of my web pages? How do I change that on the fly and then later know what that filename is when the web page is loaded?
 
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
I've tried clearing the cache and adding the dummy parameter. Neither one works. Any other suggestions. I'm just trying to allow the user to change the font size of the web pages they are viewing and the pages refer to a css file.
 
Last edited:
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
I've attached an example project of the text size not changing after changing css file and then reloading web page.
 

Attachments

  • css.zip
    11.3 KB · Views: 343
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Change your code to:
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Public WebView1 As WebView
   Private html As String
End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)
   NavControl.ToolBarVisible = True
   html = File.ReadString(File.DirAssets, "webpage.html")
   Page1.RootPanel.LoadLayout("LayoutWebView1")
   WebView1.LoadHtml(html)
   Dim b3, bspace As BarButton
   bspace.InitializeSystem(bspace.ITEM_FLEXIBLE_SPACE, "")
   b3.InitializeText("Change Font Size", "Font")
   Page1.ToolbarButtons = Array(bspace, b3, bspace)
End Sub

Sub Page1_BarButtonClick (Tag As String)
   If Tag = "Font" Then
     WebView1.LoadHtml(html.Replace("body{font-size:medium;}", _
       "body{font-size:x-large;}"))
   End If
End Sub

And add the css file to the main file:
SS-2014-12-21_10.02.20.png
 
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
When the user changes the font size, I want that font change to stick, no matter what page they are viewing. There are hundreds of pages. I don't want to read the html and change it before loading each and every page. Is there a way to accomplish this task without having to insert the css in the web page? I want to keep it in the css file so that I don't have to change every page on the fly.

If the answer is no, then how do I insert that css into the web page on the fly?
 
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
Ok. What's the command to inject that css?

I'm using LoadUrl, not LoadHtml. I will need to navigate to a web page with the loadurl command and then inject the css into that page so that it displays the correct font size to the user.
 
Last edited:
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
What's the command to inject javascript? I'm not sure what to add after looking at the page.
 
Upvote 0
Top