B4J Question Catch pop-up with WebEngine

jmon

Well-Known Member
Licensed User
Longtime User
Hello,

I would like to be able to catch pop-up from webpages, such as the alerts and prompts. I need to display those pop up in the webview, because I need the user to log in with windows credentials. I have tried using the CreateEvent method from JavaObject and calling the onAlert Method (http://docs.oracle.com/javase/8/javafx/api/javafx/scene/web/WebEngine.html#onAlertProperty) of the webengine, but no luck so far.

Can someone help me? I can't figure it out.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
    MainForm.Show
  
    we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
    wvjo = wv
    we = wvjo.RunMethod("getEngine",Null)  
    Dim e As Object = we.CreateEvent("javafx.scene.web.WebEngine.setOnAlert", "wv", False)
    we.RunMethod("setOnAlert", Array(e))

End Sub

Sub wv_Event(MethodName As String, Args() As Object)
    Log(MethodName)
End Sub

Thanks everyone
 

Attachments

  • CustomEvent.zip
    1.4 KB · Views: 150

jmon

Well-Known Member
Licensed User
Longtime User
The interface parameter is wrong. It should be:
B4X:
Dim e As Object = we.CreateEvent("javafx.event.EventHandler", "wv", False)
Thanks, it works, though it doesn't catch windows alert(), but only javascript alert(), so I'll look for something else.

Thanks
 
Upvote 0
Top