WebView阻止弹出窗口? [英] WebView blocking pop up windows?
问题描述
我使用 WebView
来浏览pesopay.com并且它正常工作,除非我按下提交按钮。使用谷歌浏览器等互联网浏览器会显示一个弹出式窗口,它确认您填写的信息。但是在我的Android WebView
中,当我按下提交按钮时,什么都没有发生。我想是因为 WebView
没有显示弹出窗口。
任何人都可以指出我的错在哪里?
以下是我的活动:
公共类PaymentActivity extends Activity {
字符串amount1;
@SuppressLint(SetJavaScriptEnabled)
@Override
protected void onCreate(Bundle savedInstanceState){
// TODO自动生成的方法存根
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);
我的网页:
<!DOCTYPE html PUBLIC - // W3C // DTD HTML 4.01 Transitional // ENhttp://www.w3.org/TR /html4/loose.dtd\">
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = ISO-8859-1>
< script type =text / javascript>
函数setValue(amount1){
myValue = amount1;
document.getElementById(amount)。value = myValue;
}
< / script>
< script type =text / javascript>
函数rand(n)
{
document.getElementById(orderRefId)。value =(Math.floor(Math.random()* n + 1));
}
< / script>
< / head>
< body onLoad =rand(200000)>
<! -
注意:https://www.pesopay.com/b2c2/eng/payment/payForm.jsp用于实时付款URL
https://test.pesopay。 com / b2cDemo / eng / payment / payForm.jsp用于测试付款URL
- >
< form method =POSTname =frmPaymentaction =https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp>
< table>
< tbody>
< tr>
< td>订单参考编号(您发现的每笔交易的参考编号):< / td>
< td>< input type =textid =orderRefIdname =orderRefvalue =Test-001/>< / td>
< / tr>
< tr>
< td>金额:< / td>
< td>< input type =textname =amountid =amountvalue =/>< / td>
< / tr>
< tr>
< td>货币代码 - 菲律宾比索为608,美元为840:< / td>
< td>< input type =textname =currCodevalue =608/>< / td>
< / tr>
< tr>
< td>语言:< / td>
< td>< input type =textname =langvalue =E/>< / td>
< / tr>
< tr>
< td>商家ID(发给您的商家识别码 - 测试帐户与真实帐户之间的商家ID不一样):< / td>
< td>< input type =textname =merchantIdvalue =18056869/>< / td>
< / tr>
< tr>
< td>交易失败后重定向至网址:< / td>
< td>< input type =textname =failUrlvalue =http://www.yahoo.com?flag=failed/>< / td>
< / tr>
< tr>
< td>成功交易后重定向至网址:< / td>
< td>< input type =textname =successUrlvalue =http://www.google.com?flag=success/>< / td>
< / tr>
< tr>
< td>取消交易后重定向至网址:< / td>
< td>< input type =textname =cancelUrlvalue =http://www.altavista.com?flag=cancel/>< / td>
< / tr>
< tr>
< td>付款类型(正常销售或授权即持有付款):< / td>
< td>< input type =textname =payTypevalue =N/>< / td>
< / tr>
< tr>
< td>付款方式 - 更改为全部,用于账户中所有激活的付款方式,仅用于BancNet借记卡付款更改为BancNet,仅用于GCash移动付款更改为GCASH,更改仅用于信用卡付款的CC:< / td>
< td>< input type =textname =payMethodvalue =ALL/>< / td>
< / tr>
< tr>
< td>备注:< / td>
< td>< input type =textname =remarkvalue =Asiapay Test/>< / td>
< / tr>
<! - < tr>
< td>重定向:< / td>
< td>< input type =textname =redirectvalue =1/>< / td>
< / tr> - >
< tr>
< td>< / td>
< / tr>
< input type =submitvalue =Submit>
< / tbody>
< / table>
< / form>
< / body>
< / html>
如果我正确的话,用于从Android调用JavaScript函数的JavaScriptInterface 。
p> http://www.codeproject.com/Articles/392603/Android-addJavaScriptInterface或者查看一些网页设置:
http://developer.android.com/reference/android/webkit/WebSettings.html#setSupportMultipleWindows%28boolean
试着把这段代码放在onCreate()中。
webView.getSettings()。setPluginsEnabled(true);
webView.getSettings()。setAllowFileAccess(true);
webView.getSettings()。setJavaScriptCanOpenWindowsAutomatically(true);
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);
这篇关于WebView阻止弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!