How to make WebView "forget" its position?

boten

Active Member
Licensed User
Longtime User
I'm trying to display several HTML files which are in the Files folder of the project.
the code copies the file from DirAssets to DirInternal with a fixed name and then displays the file.
B4X:
If File.Exists(File.DirInternal,"aa.htm") Then File.Delete(File.DirInternal,"aa.htm")
File.Copy(File.DirAssets,"file[i]n[/i].htm",File.DirInternal,"aa.htm")
s="file:///" & File.DirInternal & "/aa.htm"
wv.LoadUrl(s)

The problem is that when the 1st file is scrolled down and then the 2nd file is loaded, it is loaded with the
"scroll position" of the previous file, that is NOT from the beginning of the 2nd file.

Any idea on how to solve that?
 

warwound

Expert
Licensed User
Longtime User
Hi.

You could try adding a dummy parameter to the URL, something like:

B4X:
Dim param As Long
param=DateTime.Now
s="file:///" & File.DirInternal & "/aa.htm?param="&param
wv.LoadUrl(s)

Tradionally a page with parameters in it's URL will not be cached by the browser - the same might apply to remembering it's scroll position.

Martin.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
Nope. Didn't help. I even tried the "no-cache" tag without any results.

I tried your WebViewExtras.pageUp(wv,True) and it DID scrolled to the top of the page, but it was "slow" (relatively speaking)
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

I think you'll have to save each webpage with a unique filename then.

Is that a problem..?

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Case Closed

But why do you need to copy the webpages from DirAssets to DirInternal before loading them in a WebView?

If you're worried that the WebView will cache a copy of each page it loads - which it likely will do - then simply clear the WebView cache each time your activity closes.

Anyway - glad that nfordbscndrd's anchor suggestion does the trick :sign0060:.

Martin.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
But why do you need to copy the webpages from DirAssets to DirInternal before loading them in a WebView?
Martin.

DirAssets contains HTML files in several sub-dirs, in addition to TTF font files and CSS files. I had "bad" experience loading files from DirAsstets/somesubfolder/A123.htm and referencing CSS & TTF files in other subdirs.... found it "easier" to copy TTF, CSS to DirInternal on Create and then copy the needed HTML on the fly.
 
Upvote 0
Top