iOS Question WebView goBack to the original position on last page

joop

Active Member
Licensed User
Longtime User
Hi,how is it possible to actually go back to the original position on last page like safari’s back/forward function.
I read this on this link:

http://stackoverflow.com/questions/24153594/uiwebview-goback-to-the-original-position-on-last-page
They say:
Web view has a scrollView property, scrollView has a contentOffset property that you can get or set.

Is this possible in B4I I didn't find this property in Webview B4i , I need to set and get this offset property
can it be done with NativeObject if yes then how ?

Joop
 

joop

Active Member
Licensed User
Longtime User
thanks, but i didn't find anything i think o_O , but i found some java script- code

in override url I get the scroll top with :

B4X:
Dim no As NativeObject = WebView1
Dim offset As Object = no.RunMethod("stringByEvaluatingJavaScriptFromString:",Array("document.body.scrollTop;"))

scroll_top =offset

Then in WebView1_PageFinished I want to set the scroll_top in WebView1_PageFinished with :
B4X:
This wil not work
Dim no As NativeObject = WebView1
no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("document.body.scrollTop ='scroll_top';"))

This works
no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("document.body.scrollTop =800;"))

But how do I get the value off scroll_top in this string ?
 
Last edited:
Upvote 0

joop

Active Member
Licensed User
Longtime User
B4X:
no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("document.body.scrollTop.value =scroll_top;"))

no not good


no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("document.getElementById('scrollTop').value ='scroll_top';"))

still not good
 
Upvote 0

joop

Active Member
Licensed User
Longtime User
Erel , how can I put a variable in this javascript line ?
I don't have experience with this.

no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("document.body.scrollTop =800;"))

I want to replace the 800 with a variable name, wich is used by B4I
I tried something but it didn 't work.
 
Upvote 0

joop

Active Member
Licensed User
Longtime User
weird it gives invalid number off parentheses ,I count four off them

B4X:
no.RunMethod($"stringByEvaluatingJavaScriptFromString:", Array("document.body.scrollTop =${scroll_top};"$))
 
Upvote 0

joop

Active Member
Licensed User
Longtime User
It works now, and go back to the original position on last page also.

thanks ,Erel
 
Upvote 0
Top