Form Submit is not working in Android 4.0. The same code is working fine in the lower versions of Android.
Find my code for our reference
<form id="login-form" data-ajax="false" method="get" action="POST">
<div id="userPassLogin">
<div id="loginFormButtondiv" style="display: none;">
Back to Login
</div>
<div id="loginDiv">
<div data-role="fieldcontain" style="border: none; margin-top: 10px;">
<input style="width: 95%" type="email" class="placeholder" name="login" id="username" placeholder="Login ID" data-theme="c" value="Test286826.User286826#alere.com" />
</div>
<div data-role="fieldcontain" style="border: none; margin-top: 0px;">
<input style="width: 95%" type="password" class="placeholder" name="password" id="password" placeholder="Password" data-theme="c" value="P#ssw0rd" />
</div>
</form>
the controller code is,
'submit #login-form' : 'onSubmit',
the Method declaration and the definition is,
onSubmit : function(event)
{
alert('Inside the Form Submit');
if(isIOS){
nativeCommunication.callNativeMethod("networkcheck://isServerHosted?");
}
if(isAndroid || mHealth.util.webHostStatus){
alert('Inside the Form Submit');
event.preventDefault();
alert('Inside the Form Submit');
if(isAndroid){
alert('Inside the Form Submit');
this.doLogin();
}
}
},
Any help will be great.
Thanks
I fixed it by override WebViewClient
private class MyWebViewClient extends WebViewClient {
public String values = "";
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("?")) {
try {
values = URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
url = url.replace("?", "%45");
String args[] = url.split("%45");
view.loadUrl(args[0]);
}else{
view.loadUrl(url);
}
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
if(values.length()>0){
if(url.contains("page2.html")){
mWebView.loadUrl("javascript:getUrlVars(\""+values+"\");");
}
}
super.onPageFinished(view, url);
}
}
Related
**hi, i was trying obtain data from a page but i don't know how to obtain this data: Chapter 120 and de url link
This is the code from page (i simplified it):
<div class="row">
<div class="col-12">
<div class="card chapters" id="chapters">
<ul class="list-group list-group-flush">
<li class="list-group-item p-0 bg-light upload-link" data-index="0">
<h4 class="px-2 py-3 m-0">
<div class="row">
<div class="col-10 text-truncate">
<a style="display: block;" class="btn-collapse" onclick="collapseChapter('collapsible490362')" role="button"> CapĂtulo 120.00</a>
</div>
</div>
</h4>
<div style="display: block;" id="collapsible490362">
<div class="card chapter-list-element">
<ul class="list-group list-group-flush chapter-list">
<li class="list-group-item">
<div class="row">
<div class="col-2 col-sm-1 text-right">
<a href="https://lectortmo.com/view_uploads/599487" class="btn btn-default btn-sm">
<span class="fas fa-play fa-2x" style="color:#2957ba"></span>
</a>
</div>
</div>
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
In this line we can see the text (Chapter 120) that i need show in TextView but i don't know how to obtain it
<a style="display: block;" class="btn-collapse" onclick="collapseChapter('collapsible490362')" role="button"> Chapter 120</a>
And in this line we can see the url that i need:
<a href="https://lectortmo.com/view_uploads/599487" class="btn btn-default btn-sm">
This is my method to obtain data parsing:
#Override
protected ArrayList<TMODatosSeleccion> doInBackground(Void... voids) {
String url = getIntent().getStringExtra("valor");
tmoDatosSeleccions.clear();
try {
Document doc = Jsoup.connect(url).get();
Elements data = doc.select("div.row>.col-10");
int size = data.size();
Log.d("doc", "doc: "+doc);
Log.d("data", "data: "+data);
Log.d("size", ""+size);
for (Element e : data) {
String numeroCap = e.select("a").attr("none");
String urlManga = e.select("div.row>.col-2").select("a").addClass("btn").attr("href").trim();
tmoDatosSeleccions.add(new TMODatosSeleccion(numeroCap, urlManga));
}
} catch (IOException e) {
e.printStackTrace();
}
return tmoDatosSeleccions;
}
Someone can help me?
Print Screen:
You could get the two links you are trying to find using:
Elements data = doc.select("div.row a");
for (Element e : data)
{
// process the link
}
Or you could get them individually using:
Elements data = doc.select("div.row>.col-10 a");
if (data.size() == 1)
{
Element e = data.get(0);
// process col-10 link
}
data = doc.select("div.row>.col-2 a");
if (data.size() == 1)
{
Element e = data.get(0);
// process col-2 link
}
The main problem you were having was that the col-2 element was not nested inside the col-10 element, so your loop would not have found any items.
My code is as shown below:
private void testInfo() {
if (InternetConnection.checkConnection(LogInActivity.this)) {
Observable<ResponseBody> results = RetroClient.getApiService()
.testInfo("Basic NTcyODQ4MDc0NzEzNTIwOToxMjhiNTNkMS1iMTc2LTQxOTEtYWJmYS1hN2RhYjIzYmFjMzk=", "application/x-www-form-urlencoded",
"John Q. Test", "Visa", "4747474747474747", 12, 25, 999, "123 A. Street",
"Orem", "UT", "84058", "USA", "4355824", "ACkwlGTtMOGNlwtLY2GIsi/MgC5bgDOQIVzPFKzapIEcnUR7XEvTfeYLeVswApKH+vW+1rgO7PwJahABSrtYgC6ZmkOTxywIb24mdyefTZpOu+h9iDdu/SYcDnBcwf/sjcntYBLPCL5+gPLCpu9YpItDhb055zf9bNDWEGdoLRbl6BPVPbYCEQH9et72KxgnPZHA3Oe05IrRiy22pP8HAzpzss8c37MjEOQB5tbfkuDUCj1pfCohsQ74JBDgc0ntG+rpv7ljFElCxO95FyVYkGhIwaMQWaplwhpWqJIIw9JRL0IRTZG+ml1QzJBgdNHyKJXJmH9Gh/yVzXU4U9gyY6d3ObUYT0ODjNwnEIAc1XSOFd+WE5XklitZynuo4MgghWfZpMl0ChofstLS5e/Np7RF0xJe8WGAAV4Jdku84mnrt/42YRW2yzpUOpKI8+VddlRDKRsmvkei8gY4yjxINocMUfnzPBmsecgW8EVO1nIBpKLW36wLJ7Bawy6MA7wULO5TyP5j9ksdn6Y5IOOT+rpiJc6+OUJZZ0I7ef6qWuE=");
// showProgressBar();
results.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ResponseBody>() {
#Override
public void onCompleted() {
unsubscribe();
}
#Override
public void onError(Throwable e) {
// hideProgressBar();
Toast.makeText(LogInActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
#Override
public void onNext(ResponseBody response) {
Log.d(TAG, "onNext: " + response.string());
}
});
} else {
Toast.makeText(LogInActivity.this, R.string.string_internet_connection_warning, Toast.LENGTH_LONG).show();
}
}
Now for this, I get the following as my response:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
</title></head>
<body>
<form method="post" action="./spr.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="k2sKy+QLc68jCgZVuadfy2ONS4SO3c0" />
<div>
<div id="PanelPleaseWait">
<div style="min-height: 10em; display: block; vertical-align: middle; text-align: center; padding-top: 100px;">
<h3>
Processing, please wait...</h3>
Please wait, your transaction is processing. Please don't hit back or stop.<br />
<img src="images/bigrotation.gif" />
</div>
</div>
</div>
<input name="ResponseCipher" type="hidden" id="ResponseCipher" value="6s31abi0RZUSAw3Iwk0db9irVWKTi2+UtpSVTUE7DKlhWqLd1WBlQ==" /></form>
</body>
</html>
<script type="text/javascript">
document.forms[0].action='http://krl.in/';
document.forms[0].submit();
</script>
Here, what I want is , I want to access value of input with id ResponseCipher. What should I do to achieve that?
Jsoup is a library lets you parse numerous HTML tags/attributes off String.
Just parse your desire input Id and you should access the value as well.
Take a look at the following sources.
Parsing HTML in Android with Jsoup
Parsing input element using JSoup
I am loading a url into webview using web.loadUrl(url);. Now i want to remove part the body content when the url finished loading.
Data from the url is as follows :
<html>
<body>
<div class="header" data-role="header" data-theme="a">
<a data-icon="back" class="header-icon" data-iconpos="notext" href="mymob-web-mobile/restricted/menu.xhtml" data-ajax="false"> <span>Back</span> </a>
<!--Title-->
<h1>???help.main.title???</h1>
</div>
<div id="well">Hello World</div>
<body>
</html>
I want to remove this part in the url
<div class="header" data-role="header" data-theme="a">
<a data-icon="back" class="header-icon" data-iconpos="notext" href="mymob-web-mobile/restricted/menu.xhtml" data-ajax="false"> <span>Back</span> </a>
<!--Title-->
<h1>???help.main.title???</h1>
</div>
After some researh i come to this solution:
web= (WebView)findViewById(R.id.web);
web.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url)
{
web.loadUrl("javascript:var con = document.getElementByTagName('<div class=\"header\" data-role=\"header\" data-theme=\"a\"> '); " +
"con.style.display = 'none'; ");
}
});
web.clearCache(true);
web.clearHistory();
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.loadUrl(Constant.URL_AIDE, headers);
But the div element is not being removed.
a summery is , div to remove
<div class="header" data-role="header" data-theme="a">
<a data-icon="back" class="header-icon" data-iconpos="notext" href="mymob-web-mobile/restricted/menu.xhtml" data-ajax="false"> <span>Back</span> </a>
<!--Title-->
<h1>???help.main.title???</h1>
</div>
expected result
<html>
<body>
<div id="well">Hello World</div>
<body>
</html>
any idea please
You can use getElementsByClassName() to access the div. Here is my solution please try it.
web.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url){
web.loadUrl("javascript:document.getElementsByClassName('header')[0].style.display=\"none\";");
}
})
Your JavaScript is incorrect. There is no such thing as getElementByTagName, other than getElementById other getElements... functions return a list of nodes. It should be something like:
[].slice.call(document.getElementsByClassName("header")).forEach(function(element) {element.style.display = 'none';});
I'm using WebView to browse pesopay.com and it works properly, except when I pressed the submit button. Using internet browsers like Google Chrome will show a pop up window, it confirms the information you filled. But in my Android WebView nothing happened when I pressed the submit button. I think because WebView is not enabled to display a pop up window.
Can anyone point me what is wrong?
Here is my activity:
public class PaymentActivity extends Activity {
String amount1;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.payment);
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
amount1 = extras.getString("amount1");
}
WebView web = (WebView) findViewById(R.id.web1);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("javascript:window.onload = function(){setValue(\""+ amount1 +"\");};");
web.loadUrl("file:///android_asset/www/index.html");
}
}
My web page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function setValue(amount1) {
myValue = amount1;
document.getElementById("amount").value = myValue;
}
</script>
<script type="text/javascript">
function rand ( n )
{
document.getElementById("orderRefId").value = ( Math.floor ( Math.random ( ) * n + 1 ) );
}
</script>
</head>
<body onLoad="rand(200000)">
<!--
Note: https://www.pesopay.com/b2c2/eng/payment/payForm.jsp for live payment URL
https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp for test payment URL
-->
<form method="POST" name="frmPayment" action="https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp">
<table>
<tbody>
<tr>
<td>Order Reference No. (your reference number for every transaction that has transpired):</td>
<td><input type="text" id="orderRefId" name="orderRef" value="Test-001"/></td>
</tr>
<tr>
<td>Amount:</td>
<td><input type="text" name="amount" id="amount" value=""/></td>
</tr>
<tr>
<td>Currency Code - "608" for Philippine Peso, "840" for US Dollar:</td>
<td><input type="text" name="currCode" value="608"/></td>
</tr>
<tr>
<td>Language:</td>
<td><input type="text" name="lang" value="E"/></td>
</tr>
<tr>
<td>Merchant ID (the merchant identification number that was issued to you - merchant IDs between test account and live account are not the same):</td>
<td><input type="text" name="merchantId" value="18056869"/></td>
</tr>
<tr>
<td>Redirect to a URL upon failed transaction:</td>
<td><input type="text" name="failUrl" value="http://www.yahoo.com?flag=failed"/></td>
</tr>
<tr>
<td>Redirect to a URL upon successful transaction:</td>
<td><input type="text" name="successUrl" value="http://www.google.com?flag=success"/></td>
</tr>
<tr>
<td>Redirect to a URL upon canceled transaction:</td>
<td><input type="text" name="cancelUrl" value="http://www.altavista.com?flag=cancel"/></td>
</tr>
<tr>
<td>Type of payment (normal sales or authorized i.e. hold payment):</td>
<td><input type="text" name="payType" value="N"/></td>
</tr>
<tr>
<td>Payment Method - Change to "ALL" for all the activated payment methods in the account, Change to "BancNet" for BancNet debit card payments only, Change to "GCASH" for GCash mobile payments only, Change to "CC" for credit card payments only:</td>
<td><input type="text" name="payMethod" value="ALL"/></td>
</tr>
<tr>
<td>Remark:</td>
<td><input type="text" name="remark" value="Asiapay Test"/></td>
</tr>
<!--<tr>
<td>Redirect:</td>
<td><input type="text" name="redirect" value="1"/></td>
</tr>-->
<tr>
<td></td>
</tr>
<input type="submit" value="Submit">
</tbody>
</table>
</form>
</body>
</html>
If i am getting right , you need to use JavaScriptInterface for calling JavaScript function from Android.
Check this link which may help you :
http://www.codeproject.com/Articles/392603/Android-addJavaScriptInterface
Or check some websettings :
http://developer.android.com/reference/android/webkit/WebSettings.html#setSupportMultipleWindows%28boolean
try to put this code in onCreate()
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
The function which is responsible for dialogs in Webview is onJsAlert of WebChromeClient.
Here is sample code
public class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message, JsResult jsResult) {
// you can create your own dialog here or just return true for no pop up.
return true;
}
}
and add this to your webview:
MyWebChromeClient myWebChromeClient = new MyWebChromeClient();
webView.setWebChromeClient(myWebChromeClient);
I have an HTML form inside a WebView. The form control looks like a regular button, but actually it is an html file with a transparent background. When I press the HTML submit button, I want the result to open in the browser, not in the webview. Currently it is opening in the current WebView which is wrecking my layout.
How do I do this?
Here is my Form
<string name="googlecheckout_html_button">
<![CDATA[
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
<head>
<title>Google Checkout Button</title>
<script type=\"text/javascript\" language=\"javascript\">
function pass() {
return javaInterface.checkboxPass();
}
</script>
</head>
<body>
<form style=\"width: 121px;margin-left: auto;margin-right: auto;\" onsubmit=\"return pass();\" action=\"https://%1$sapi/checkout/v2/checkoutForm/Merchant/%2$s\" id=\"BB_BuyButtonForm\" method=\"post\" name=\"BB_BuyButtonForm\">
<input name=\"item_name_1\" type=\"hidden\" value=\"%3$s\" />
<input name=\"item_description_1\" type=\"hidden\" value=\"%3$s\" />
<input name=\"item_quantity_1\" type=\"hidden\" value=\"1\" />
<input name=\"item_price_1\" type=\"hidden\" value=\"%4$s\" />
<input name=\"item_currency_1\" type=\"hidden\" value=\"%5$s\" />
<input name=\"_charset_\" type=\"hidden\" value=\"utf-8\" />
<input type=\"hidden\" name=\"shopping-cart.items.item-1.merchant-private-item-data\" value=\"%6$s\" />
<input alt=\"Pay With Google Checkout\" src=\"https://%1$sbuttons/buy.gif?merchant_id=%2$s&w=121&h=44&style=trans&variant=text&loc=en_US\" type=\"image\" />
</form>
</body>
</html>
]]>
</string>
I am then using String.format(arg...) to populate the fields with appropriate values.
Here is by WebView
String form = String.format(getString(R.string.googlecheckout_html_button),
host,
merchantId,
item_name_1,
item_price_1,
item_currency_1,
private_item_data
);
if(Logging.DEBUG) Log.d(TAG, form);
browser = new WebView(ActivityActivate.this);
browser.setBackgroundColor(0);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
browser.getSettings().setSupportZoom(true);
browser.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view,
String url) {
return false;
}
});
//browser.getSettings().setLoadsImagesAutomatically(true);
browser.addJavascriptInterface(new JavascriptInterface(), "javaInterface");
//browser.loadData(header+formData+footer, "text/html", "UTF-8");
browser.loadDataWithBaseURL("https://checkout.google.com", form, "text/html", "UTF-8", null);
llPaymentButtons.addView(browser);
Forms are submitted to servers not to browsers. Make sure you have a correct URL where you are submitting the form.
To solve your problem you must override WebViewClient.shouldOverrideUrlLoading(..):
webview.setWebViewClient( new WebViewClient() {
public void shouldOverrideUrlLoading (WebView view, String url) {
return false;
}
});