B4J Tutorial WebView

Been trying WebView and WebEngine.

Here's a little example of using both. (requires additional library to run)

Shows how to retrieve the hyperlinks in a page and put them in a comboBox, also implement forward and back and home buttons.
Type in a web address (http://www...) or file address (file:c:\somefile.txt) to have it displayed in the webview.

The examples get progressively more complex. (easiest - webview, hardest webview4)

webview - displaying web pages

webview2 - has example of an inline web page with inline css sheet.

webview3 - rudimentary file downloading can be modified for any type file, example is for text type.

webview4 - has a media player defined - plays flv files. (messy, player is on top of the web window)

On first looks, this appears to be quite a safe browser, as you have to instigate the download.
 

Attachments

  • webview.zip
    1.9 KB · Views: 2,129
  • webview2.zip
    2.6 KB · Views: 1,307
  • webview3.zip
    3.6 KB · Views: 1,255
  • webview4.zip
    3.8 KB · Views: 1,442
Last edited:

Daestrum

Expert
Licensed User
Longtime User
You have various methods of doing that, you can read the entire file into a string and use 'loadContent' (see contenetButton sub) or use 'load' and prepend 'file:' before the file address (ie 'file:' & file-address).
 

John Woodsmall

Active Member
Licensed User
Longtime User
I downloaded your zip's and I need to unserstand how to use them.
(they are b4j).
what is step #
1.
2.
3.
I could say I am new to all of this, but you must know that by my question.
I am trying to load an html page, with results on it.
thanks

john
 

Daestrum

Expert
Licensed User
Longtime User
if the wepage is remote or local to your machine, you use load(url)
where url can be http://........ or file:c:/........

https:// does not appear to work ( i need to read up more on the handlers required)

If its in-line you use loadContent(string). ( see contentButton_MouseClicked sub)
 

jmon

Well-Known Member
Licensed User
Longtime User
Hi, I have a question regarding this event:
B4X:
Sub wv1_MouseClicked (EventData As MouseEvent)
mousex = EventData.X    ' get the link that was clicked on page
mousey = EventData.Y
js.evalString("var element = doc.elementFromPoint(" & mousex &","& mousey & ");") ' get the hyperlink
Log(js.engineGet("element"))
End Sub

Why does the log(js.engineGet("element") returns
B4X:
sun.org.mozilla.javascript.internal.Undefined@315883
and sometimes return "null" when clicking on the "B4J Rules" link in the "content" page?
 

Daestrum

Expert
Licensed User
Longtime User
Sorry for delay in reply.
I would guess the mouse has missed the area the control is in, and so does not register a control and returns null.
 

jmon

Well-Known Member
Licensed User
Longtime User
Why does the log(js.engineGet("element") returns
B4X:
sun.org.mozilla.javascript.internal.Undefined@315883
and sometimes return "null" when clicking on the "B4J Rules" link in the "content" page?
Update: It seems that this issue is solved in JavaFX 8.
 

Daestrum

Expert
Licensed User
Longtime User
Just tried both of the links you posted - they both give me google login screen, which is what I would expect as I am not logged into Google.

As an afterthought, I am using Java 8 which has the later version of Javafx built in (I believe), maybe that's why the https: is now working , whereas when I wrote the original tutorial, it wasn't working.
 
Last edited:

FrenchDeveloper

Member
Licensed User
Longtime User
It's normal that these links drive you first to login screen. After login, they need to drive you to gmail or to Google drive. Gmail works but there is a problem with Google drive (see screenshot below). Both links work perfectly in Firefox. I tried with Scene builder 2.0 b20 + Java 7 and 8 but the problem is exactly the same.
 

Attachments

  • Google drive.png
    Google drive.png
    13.2 KB · Views: 647

Daestrum

Expert
Licensed User
Longtime User
Just tried google drive url
1, Got Google Login box
2, Signed in
3, Got drive window showing my files (which I forgot I had on there :) )

Seems to be working fine here (Java 8_20)
 

supriono

Member
Licensed User
Longtime User
dear daestrum:
great sample code...n it work

i want to read only text in same web.
but in your code i don't now how to get string text form website.
 

CHAUVET

Member
Licensed User
Longtime User
Hi,

How can we know the value of the scroll of a webview.

I have a web page that is very long and I have to use the vertical scoll to see the bottom of the page.

How to know the position (value) of the scroll?
And can we change the value (position) of the scroll by programming?

Thank you for your help,
 

CHAUVET

Member
Licensed User
Longtime User
Thanks Erel,

For go to scroll position on Webview :
With JavaObjet -> window.scrollTo(1, 200) ' 200 px from top of webview

B4X:
Dim joWV As JavaObject = WebView1
joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String("window.scrollTo(1, 200);"))

For get value of scroll in a web page :
With JavaObjet -> document.body.scrollTop ' Value on log window is in px from top of webview
B4X:
Dim joWV As JavaObject = WebView1
Log(joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String("document.body.scrollTop;")))
 

alienhunter

Active Member
Licensed User
Longtime User
Nice it works very well ,
better then firefox with our database

i got a question how should i make this work in the webpage there are export features like excel or pdf print
but right now they do not work with webview .
Is there a soultion for this ?
thanks AH


2015-02-03_9-02-03.png
 
Top