Download courcecode from webview

tudorf

Active Member
Licensed User
Longtime User
Is it possibel to download the sourcecode from a webview?

I mean not the sourcecode from a webadress with httputils.

The problem: The webside does not accept my username and Password with HTTPUtils. I have ask Klaus but he can´t help me.

I have found the Sample “SimpleSearch” from warwound but I understand how it works.

I open the webside Geocaching - The Official Global GPS Cache Hunt Site with a webview. Then I can log in und I see varius Information.

Thanks Martin
 

Attachments

  • correct.JPG
    correct.JPG
    83.7 KB · Views: 201
  • wrong_password.JPG
    wrong_password.JPG
    35.5 KB · Views: 186

tudorf

Active Member
Licensed User
Longtime User
Hello Erel

Sorry. I understand what you mean. I must change the Browser Google in firefox in the webview on my Samsung S3 ?

Martin
 
Upvote 0

tudorf

Active Member
Licensed User
Longtime User
Thanks for the information. English is not my language.

Unfortunately I can´t Java, Html or CSS.

Martin
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

Take a look at the attached project, it's some old code i put together for the old JSInterface library.
I've updated it to work with WebViewExtras:

B4X:
'Activity module
Sub Process_Globals
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim WebViewExtras1 As WebViewExtras
   Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("layoutMain")
   
   Activity.AddMenuItem("Save webpage", "SaveWebpage")
   
   '   add the B4A javascript namespace to the WebView
   WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
   '   now load a web page
   WebView1.LoadUrl("http://www.b4x.com/forum/index.php")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub WebView1_PageFinished (Url As String)
   '   This Sub is called each time a new web page has been loaded in WebView1
   '   http://www.b4x.com/android/wiki/index.php/WebView#PageFinished_.28Url_As_String.29
   Log("WebView1_PageFinished")
   Log("Webpage Url: "&Url)
   Dim Javascript As String
   Javascript="B4A.CallSub('WebView1_SaveWebPage', true, '"&Url&"', document.documentElement.outerHTML)"
   Log("Javascript to execute: "&Javascript)
   '   When WebView1 executes the Javascript it will get the web page content and call the Sub WebView1_SaveWebPage passing the web page Url and content as Strings
   WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub

Sub WebView1_SaveWebPage(Url As String, PageContent As String)
   '   WebView1 will call this Sub via the B4A Javascript interface
   Log("WebView1_SaveWebPage")
   Log("Webpage Url: "&Url)
   Log("Webpage Content: "&PageContent)
   '   Log may truncate a large page so you'll not see all of the HTML in the log but the PageContent String will still contain all of the web page content
   
   Log("Now you now want to save PageContent")
End Sub

Sub SaveWebpage_Click
   Dim Javascript As String
   Javascript="B4A.CallSub('WebView1_SaveWebPage', true, '"&WebView1.Url&"', document.documentElement.outerHTML)"
   WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub

It uses WebViewExtras to execute this javascript:

B4X:
B4A.CallSub('WebView1_SaveWebPage', true, 'http://www.b4x.com/forum/index.php', document.documentElement.outerHTML)

So once the page has loaded (or when you use the MenuItem) the javascript tells the webpage to send it's HTML to the B4A Sub WebView1_SaveWebPage.

Hope that helps.

(another) Martin.
 

Attachments

  • SaveHTML.zip
    6.4 KB · Views: 190
Upvote 0
Top