Webview without header and footer.

FDisk

Member
Hi All, is there a way to load a page with Webview without a header and a footer?
Or maybe is it possible to stretch the page so the header and footer are out of view?

Example:
I would like content to be the only viewable area.

PwFpE.png



I tried just stretching the window in designer but that didn't work. :sign0163:
 

FDisk

Member
You might be able to do it by injecting JavaScript code that will hide the header and footer with WebViewExtra library (available to licensed users only).

Oh, thanks. So there is no way to do this with WebView. :(

Another question I wanted to ask about WebView.
When I change the orientation from portrait to landscape the WebView I guess refreshes itself and goes back to the index page.
Is it possible to keep the WebView showing the current page I on when the orientation is changed?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Oh, thanks. So there is no way to do this with WebView. :(

Another question I wanted to ask about WebView.
When I change the orientation from portrait to landscape the WebView I guess refreshes itself and goes back to the index page.
Is it possible to keep the WebView showing the current page I on when the orientation is changed?

I'm not sure what your original question about headers and footers was but here's a simple way to save and restore the currently loaded page in a WebView on orientation change:

B4X:
Sub Process_Globals
   Dim UrlToLoad As String
End Sub

Sub Globals
   Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      UrlToLoad="http://www.worldweatheronline.com/v2/weather.aspx?q=PE30"
   End If
   
   WebView1.Initialize("WebView1")
   Log("Activity_Create loading Url: "&UrlToLoad)
   WebView1.LoadUrl(UrlToLoad)
   
   Activity.AddView(WebView1, 0, 0,100%x, 100%y)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
   Log("New web page loaded and UrlToLoad updated to: "&Url)
   UrlToLoad=Url
End Sub

A Process_Global variable UrlToLoad is updated each time a new web page is loaded.
When Activity_Create is executed it either loads a default web page (FirstTime=True) or restores the last loaded web page.

Saving and restoring a WebView is problematic, you can catch the Back key press and then call the WebView Back method to return to the previously loaded Url if one exists:

B4X:
'Activity module
Sub Process_Globals
   Dim UrlToLoad As String
End Sub

Sub Globals
   Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      UrlToLoad="http://www.worldweatheronline.com/v2/weather.aspx?q=PE30"
   End If
   
   WebView1.Initialize("WebView1")
   Log("Activity_Create loading Url: "&UrlToLoad)
   WebView1.LoadUrl(UrlToLoad)
   
   Activity.AddView(WebView1, 0, 0,100%x, 100%y)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
   Log("New web page loaded and UrlToLoad updated to: "&Url)
   UrlToLoad=Url
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
   If keycode=KeyCodes.KEYCODE_BACK Then
      WebView1.Back   '   go to the last loaded web page in the WebView history if one exists - but how we be sure a previous page exists?
      Return True      '   returning True indicates that the event has been handled
   Else
      Return False   '   the default Back button behaviour will now be executed
   End If
End Sub

BUT if you visit a few web pages and then change your device orientation, you'll find that all previously visited web pages (in the WebView history) have been discarded - Back will not return to a web page viewed before the last orientation change.

Finally you might ask how to restore the scroll position in a WebView on orientation change - it's been asked before a few times with no concrete solution available: http://www.b4x.com/forum/basic4andr...save-current-url-page-position.html#post80325.

Martin.
 

Attachments

  • WebViewRestore.zip
    6 KB · Views: 232
Upvote 0
Top