Android Question B4X - B4XPages: Back button and webview

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
I have a webview rendering a web page listing the headings of a list of posts / articles where the user can click the "read more ..." link to open the article.

I state that I am not particularly familiar with web views, but the goal in this case is to allow the user to return to the list of articles, after having opened one. How is it possible to manage the "back" button so that it performs the back functionality of the web page displayed in the webview?

At the moment the back button performs a back of the B4XPage.

Thanks in advance for your suggestions.

Luca.
 

josejad

Expert
Licensed User
Longtime User
Hi:

I can't test it right now (I'm getting an error installing to the device), but, have you try with:

B4X:
'Return True to close, False to cancel
Private Sub B4XPage_CloseRequest As ResumableSub
    If WebView1.IsInitialized Then
        WebView1.Back
        Return False
    End If
    Return True
End Sub
 
Upvote 1

luke2012

Well-Known Member
Licensed User
Longtime User
Hi:

I can't test it right now (I'm getting an error installing to the device), but, have you try with:

B4X:
'Return True to close, False to cancel
Private Sub B4XPage_CloseRequest As ResumableSub
    If WebView1.IsInitialized Then
        WebView1.Back
        Return False
    End If
    Return True
End Sub

Hi Josè. First of all thanks for your appreciated reply.
I try your code and then I tell you.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
Hi:

I can't test it right now (I'm getting an error installing to the device), but, have you try with:

B4X:
'Return True to close, False to cancel
Private Sub B4XPage_CloseRequest As ResumableSub
    If WebView1.IsInitialized Then
        WebView1.Back
        Return False
    End If
    Return True
End Sub

I updated the code in order to handle the different back method names and to handle the B4XPage back and it works fine on Android.

Within B4i I got a sintax error that says: "unknown member: url".
Searching among the webview methods in the B4i version, in fact, there is no url method (unlike the B4A version).

So, mainly for me now this is the problem. That is, the vebview (in my project it is that of the news list) is opened via a button on the "Home" page of the app.

The webview opens a web page that lists the titles of the news (articles) and the user can open the detail of the single article by touching the image. The code then allows you to navigate (back) from the full article page to the news (articles) list page.

If you press the back button and you are on the news list (https://mysite.com/content/news) the code related to the webview is not executed but instead the B4XPage "home" is displayed (then the navigation switches to B4XPages ).

o now, the main problem is that this code only works correctly on the android version of the app but instead i should make it work on the ios version of the app as well.

Some idea to solve this ?

B4X:
'Return True to close, False to cancel
Private Sub B4XPage_CloseRequest As ResumableSub
    If WebView1.IsInitialized Then
        If WebView1.Url <> "https://mysite.com/content/news" Then
            #if B4A
                WebView1.Back 'android
            #End If
            #if B4i
                WebView1.GoBack 'iOS
            #End If
            Return False
        End If
    End If
    B4XPages.ShowPage("AppHome")
    Return True
End Sub
 
Last edited:
Upvote 0
Top