iOS Question how to go back in webview and how to download pdf file

Baris Karadeniz

Active Member
Licensed User
I try to make a webview project. How can I provide go back from last page to previous page? And the second question is; when one button is clicked at the web site, pdf file is opened on the screen. Instead of opening pdf file, how can I download pdf file?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can call WebView.GoBack to go to the previous page.

Handle the OverrideUrl event. If the link ends with pdf then use HttpUtils2 to download the pdf and return true. Something like:
B4X:
Sub WebView_OverrideUrl (Url As String) As Boolean
   If Url.EndsWith(".pdf") Then
     Dim j As HttpJob
     j.Initialize("pdf", Me)
     j.Download(Url)
     Return True
   Else
     Return False
   End If
End Sub
https://www.b4x.com/android/forum/threads/class-httputils2.46565/#content
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
I started with beginner's guide but there are many things so I need to ask also. To use the codes above I downloaded iHttpUtils2.zip and extracted. Will I add it to the additional libraries?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
To use the codes above I downloaded iHttpUtils2.zip and extracted. Will I add it to the additional libraries?
No. You need to use Project - Add Existing Modules and add the two modules (HttpJob and HttpUtils2Service).

You also need to add a reference to iHTTP and iStringUtils libraries.
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
Sorry, I didn't understand your question. Here are the codes. I have one log "Sub JobDone not found (warning #25)"


'Code module
#Region Project Attributes
#ApplicationLabel: TAKSİ'M
#Version: 2.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#Target: iPhone, iPad
#MinVersion: 7
#PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page

Private WebView1 As WebView
End Sub

Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page1"
Page1.RootPanel.Color = Colors.White
Page1.RootPanel.LoadLayout("Layout1")
NavControl.ShowPage(Page1)
WebView1.LoadUrl("http://www.taksi-m.com.tr/track")
End Sub

Sub WebView_OverrideUrl (Url As String) As Boolean
If Url.EndsWith(".pdf") Then
Dim j As HttpJob
j.Initialize("pdf", Me)
j.Download(Url)
Return True
Else
Return False
End If
End Sub
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
you have to add

B4X:
Sub JobDone (Job As HttpJob)
end sub

and between them the thing you want to do when the download is complete
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
Ok. I added JobDone. Now there is no log. But I didn't understand what Erel says;

What is the EventName value of the WebView? It must match the the sub prefix (WebView in the code I posted).
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Ok. I added JobDone. Now there is no log. But I didn't understand what Erel says;

What is the EventName value of the WebView? It must match the the sub prefix (WebView in the code I posted).
he means : Go to designer script , click on the webview you will see eventname under main. It must be WebView exactly not webview1 or stg like that in order for Erel's vode to work..
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
Ok. I changed the Erel's line as below. Because it is WebView1 in designer script.

Sub WebView1_OverrideUrl (Url As String) As Boolean

Now, pdf file is not opened on the screen. But it ask choices like Open, copy, add. I want directly download pdf file. It asks because of device settings?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Probaby, it is not possible to download directly because of security. But I am not sure.
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
Erel, if I have Page2, is it possible to open pdf file in page2? If it is possible then it will be nice to go back to Page 1 with "HideBackButton".

In the codes you sent below, is it possible to say that open pdf in page2 (........) ?


Sub WebView1_OverrideUrl (Url As String) As Boolean
If Url.EndsWith(".pdf") Then
.......................................
NavControl.ShowPage(Page2)
Return True
Else
Return False
End If
End Sub
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
Erel, I added Page2. And wrote the line as shown above. When pdf clicked in web site, Page2 is opened and can go back to Page1 with "HideBackButton". It is very nice. Just I need to open pdf file in Page2. Which command should I add to the codes above?
 
Upvote 0
Top