Hello dear developers
Can anyone advice me about properly usage of WebviewExtras?
I'm trying to replace webview elements and emulate submit button but got fail
Activity
Html
Can anyone advice me about properly usage of WebviewExtras?
I'm trying to replace webview elements and emulate submit button but got fail
Activity
B4X:
Sub Globals
Dim Label1, Label2, Label3 As Label
Dim Edittext1, Edittext2, Edittext3 As EditText
Dim Webview1 As WebView
Dim WebviewExtras1 As WebViewExtras
Dim Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Label1.Initialize("Label1")
Label1.TextSize = 14
Label1.Text = "Host (URL):"
Label2.Initialize("Label2")
Label2.TextSize = 14
Label2.Text = "Username:"
Label3.Initialize("Label3")
Label3.TextSize = 14
Label3.Text = "Password:"
Edittext1.Initialize("Edittext1")
Edittext1.TextSize = 14
Edittext1.SingleLine = True
Edittext1.Text = "http://localhost:8080/index.html"
Edittext2.Initialize("Edittext2")
Edittext2.TextSize = 14
Edittext2.SingleLine = True
Edittext2.Text = "admin"
Edittext3.Initialize("Edittext3")
Edittext3.TextSize = 14
Edittext3.SingleLine = True
Edittext3.Text = "1234567890"
Edittext3.PasswordMode = True
Button1.Initialize("Button1")
Button1.TextSize = 14
Button1.Text = "Login"
Webview1.Initialize("Webview1")
Webview1.JavaScriptEnabled = True
Webview1.Visible = False
WebviewExtras1.Initialize(Webview1)
Activity.AddView(Webview1, 0, 0, 100%x, 100%y)
Activity.AddView(Label1, 10dip, 10dip, 100%x - 20dip, 20dip)
Activity.AddView(Edittext1, 10dip, 30dip, 100%x - 20dip, 30dip)
Activity.AddView(Label2, 10dip, 60dip, 100%x - 20dip, 20dip)
Activity.AddView(Edittext2, 10dip, 80dip, 100%x - 20dip, 30dip)
Activity.AddView(Label3, 10dip, 110dip, 100%x - 20dip, 20dip)
Activity.AddView(Edittext3, 10dip, 130dip, 100%x - 20dip, 30dip)
Activity.AddView(Button1, 10dip, 160dip, 100%x - 20dip, 45dip)
Activity.AddMenuItem("Go Back", "Menuitem1")
End Sub
Sub Menuitem1_Click()
Label1.Visible = True
Label2.Visible = True
Label3.Visible = True
Edittext1.Visible = True
Edittext2.Visible = True
Edittext3.Visible = True
Button1.Visible = True
Webview1.Visible = False
End Sub
Sub Button1_Click()
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Edittext1.Visible = False
Edittext2.Visible = False
Edittext3.Visible = False
Button1.Visible = False
Webview1.Visible = True
Webview1.LoadUrl(Edittext1.Text)
End Sub
Sub Webview1_PageFinished (Url As String)
Dim Javascript As String
Javascript = "document.forms['logon'].getElementById('username').value='" & Edittext2.Text & "';" & _
"document.forms['logon'].getElementById('password').value='" & Edittext3.Text & "';" & _
"document.forms['logon'].submit();"
WebviewExtras1.executeJavascript(Javascript)
Activity.Title = WebviewExtras1.GetTitle
End Sub
B4X:
<html>
<head>
<title>Login</title>
</head>
<form action="./login.php" method="post">
<div id="logon">
<span>
Username: <input type="text" name="username" />
<br>
Password: <input type="password" name="password" />
<br>
<input type="submit" name="login" value="Login" />
</span>
<input type="hidden" name="token" value="abcdef1234567890">
</div>
</form>
</body>
</html>