Links Inside Webview

abhishek007p

Active Member
Licensed User
Longtime User
Hi,

i am showing a HTML page to the user using webview control. at the bottom of the page i have added links to website that user can visit. but the problem is when the user clicks on the link, the page gets opened inside the webview even through i have used _blank as target for my links.

i want that if a user click certain links inside webview it should open the device's web browser.

any help on this?

thanks,
abhishek
 

abhishek007p

Active Member
Licensed User
Longtime User
Thanks.
but that would make all links inside webview to open in web browser. i only want certain links to open in browser. is there an alternative? like inserting a HTML tag to the link and only those with that tag will open.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Try this:

B4X:
Sub WebView1_OverrideUrl(Url As String) As Boolean
   ToastMessageShow("Loading Page..." & CRLF & Url, False)
   'The character below ">" can be anything you want to add to the Link
   If Url.StartsWith(">") Then
      Dim p As PhoneIntents
      StartActivity(p.OpenBrowser(Url))
   Else
      WebView1.LoadUrl(Url)
   End If   
   Return False
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Try this:

B4X:
Sub WebView1_OverrideUrl(Url As String) As Boolean
    ToastMessageShow("Loading Page..." & CRLF & Url, False)
    'The character below ">" can be anything you want to add to the Link
    If Url.StartsWith(">") Then
        Dim p As PhoneIntents
        StartActivity(p.OpenBrowser(Url))
    Else
        WebView1.LoadUrl(Url)
    End If    
    Return False
End Sub
Shouldn't we get the '>' out of the link when loading? :)
Actually I don't really know how the browser will handle this extra char, perhaps it will not have a problem, but just to be sure:
B4X:
StartActivity(p.OpenBrowser(Url.substring(1)))
 
Upvote 0
Top