iOS Question Ricaricare una pagina partendo dal top della pagina in b4i

ken87

Active Member
Licensed User
Longtime User
Buongiorno,
Ho postato nel forum italiano ma forse questa è la sezione più corretta
Ho una barra con diversi pulsanti uno carica sul componete WebView la pagina principale
uno torna indietro alla pagina precedente
mentre uno dovrebbe refresh della pagina corrente partendo dal top

Un pò di tempo in b4i scrivevo

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private paginaweb As WebView
    
    Public paginacaricata As String
    
    
    
End Sub


sub refresh_Click

   #If B4a

    paginacaricata= paginaweb.Url

    paginaweb.LoadUrl(paginacaricata)

     #else B4i

'    Dim no As NativeObject= paginaweb
'    no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("window.location.reload();"))

    #end if





La soluzione in b4a funziona in b4i non funziona più

Mi è stato suggerito questo

B4X:
dim nome = RunJavaScript("window.location.href;")


B4X:
Private Sub RunJavaScript (js As String) As ResumableSub
    #if B4A
    WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
    Wait For Process_Html(html As String)
    Return html
    #Else If B4J
    Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js))
    #Else If B4i
    Dim sf As Object = paginaweb.EvaluateJavaScript(js)
    Dim valore  As String
    sf= paginaweb.Top
    Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
    sf= paginaweb.Top
    valore = Result
    Log (valore)
    Return Result
    #end if
End Sub


Inserendo

B4X:
 sf= paginaweb.Top

Ma continua a caricarmi nel punto dove sono e non al top


Cercando in rete
Il problema potrei risolverlo ricavandomi il nome della pagina per poi ricaricarlo

tipo

B4X:
'    paginacaricata= paginaweb.Url
'    paginaweb.LoadUrl(paginacaricata)

Il problema che la proprietà Url del controllo WebView non esiste in b4i

quindi il mio problema come faccio a ricavarmi in b4i il non della pagina corrente per poi fare un LoadUr


In html il nome della pagina viene letto in questo modo


HTML:
<!DOCTYPE html>
<html>
<body>

<h1>The Window Location Object</h1>
<h2>The href Property</h2>

<p id="demo"></p>

<script>
let url = location.href;
document.getElementById("demo").innerHTML = url;
</script>

</body>
</html>

quindi in teoria dovrei scrivere una cosa del tipo

B4X:
dim nome as string = RunJavaScript("window.location.href();")

Dove la funzione restituisce il nome della pagina

Quindi dovrei modificare questa funzione in modo da restituirmi il nome della pagina ma che modifiche devo apportare?

B4X:
Private Sub RunJavaScript (js As String) As ResumableSub
    #if B4A
    WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
    Wait For Process_Html(html As String)
    Return html
    #Else If B4J
    Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js))
    #Else If B4i
    Dim sf As Object = paginaweb.EvaluateJavaScript(js)
    Dim valore  As String
    sf= paginaweb.Top
    Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
    sf= paginaweb.Top
    valore = Result
    Log (valore)
    Return Result
    #end if
End Sub

sicuramente deve restituire una stringa quindi


B4X:
Private Sub RunJavaScript (js As String) As string
Mi aiutate?

Grazie mille
 
Last edited:

ken87

Active Member
Licensed User
Longtime User
Good morning,
I posted in the Italian forum but perhaps this is the most correct section

I have a bar with several buttons one loads on the webview compose the main page

one goes back to the previous page

while one should refresh the current page starting from the top

A little time in b4i I wrote

B4X:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private paginaweb As WebView

Public paginacaricata As String



End Sub


sub refresh_Click

#If B4a

paginacaricata= paginaweb.Url

paginaweb.LoadUrl(paginacaricata)

#else B4i

' Dim no As NativeObject= paginaweb
' no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("window.location.reload();"))

#end if

Solution in b4a works in b4i no longer works
This was suggested to me



B4X:
dim nome = RunJavaScript("window.location.href;")


B4X:
Private Sub RunJavaScript (js As String) As ResumableSub
#if B4A
WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
Wait For Process_Html(html As String)
Return html
#Else If B4J
Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js))
#Else If B4i
Dim sf As Object = paginaweb.EvaluateJavaScript(js)
Dim valore As String
sf= paginaweb.Top
Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
sf= paginaweb.Top
valore = Result
Log (valore)
Return Result
#end if
End Sub


Inserendo

B4X:
 sf= paginaweb.Top

But keep charging me where I am and not at the top
Searching the net

I could solve the problem by getting the name of the page and then reloading it



B4X:
' paginacaricata= paginaweb.Url
' paginaweb.LoadUrl(paginacaricata)

The problem is that the URL property of the WebView control does not exist in b4i


so my problem how can I get the non of the current page in b4i and then do a LoadUr

In html the page name is read like this

HTML:
<!DOCTYPE html>
<html>
<body>

<h1>The Window Location Object</h1>
<h2>The href Property</h2>

<p id="demo"></p>

<script>
let url = location.href;
document.getElementById("demo").innerHTML = url;
</script>

</body>
</html>

so in theory I should write something like

B4X:
dim nome as string = RunJavaScript("window.location.href();")

Where the function returns the name of the pageSo I should change this function to return the page name but what changes do I need to make?
B4X:
Private Sub RunJavaScript (js As String) As ResumableSub
#if B4A
WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
Wait For Process_Html(html As String)
Return html
#Else If B4J
Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js))
#Else If B4i
Dim sf As Object = paginaweb.EvaluateJavaScript(js)
Dim valore As String
sf= paginaweb.Top
Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
sf= paginaweb.Top
valore = Result
Log (valore)
Return Result
#end if
End Sub

surely must return a string:


B4X:
Private Sub RunJavaScript (js As String) As string


Can you help me?
 
Upvote 0
Top