我有一个场景,我需要在网页中显示一个网址。
网址包含一个不显示的弹出窗口,显示空屏幕而不是弹出窗口。
请在下面找到我的实施方案:
webView = (WebView) instamedWebView.findViewById(R.id.webView);<br>
WebSettings settings = webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setUseWideViewPort(true);
settings.setJavaScriptEnabled(true);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLoadsImagesAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setAllowFileAccess(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
try {
String url = "https://ppay-dev.com/Payment/abc.aspx";
String postData = String postData = "amount=" + URLEncoder.encode(userName, "UTF-8") + "&FirstName=" + URLEncoder.encode(password, "UTF-8");
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
}
});
webView.postUrl(url,postData.getBytes());
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
return super.onJsAlert(view, url, message, result);
}
});
catch (Exception e){
e.printStackTrace();
}
任何人都可以建议我如何在Android WebView中显示弹出窗口
答案 0 :(得分:1)
也许您可以尝试将网络提醒覆盖为本机提醒。它对我有用。
webview.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
Log.i("TITLE", title);
}
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
}
// OVERRIDE WEB CONFIRM ALERT TO NATIVE ALERT
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(VideoTutorial.this)
.setTitle("DOMINOS SAYS:")
.setMessage(message)
.setPositiveButton(android.R.string.ok, (dialog, which) -> result.confirm())
.setNegativeButton(android.R.string.cancel, (dialog, which) -> result.cancel())
.create().show();
return true;
}
// OVERRIDE WEB ALERT TO NATIVE ALERT
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(VideoTutorial.this)
.setTitle("DOMINOS SAYS:")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
(dialog, which) -> result.confirm())
.create().show();
return true;
}
// OVERRIDE WEB PROMPT ALERT TO NATIVE ALERT PROMPT
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) {
new MaterialDialog.Builder(VideoTutorial.this)
.title("DOMINOS SAYS:")
.content(message)
.inputType(InputType.TYPE_CLASS_TEXT)
.inputRangeRes(2, 20, R.color.dominoRed)
.input("No 1 Pizza Fav", "", (dialog, input) -> result.confirm(input + ""))
.positiveText("OK")
.negativeText("CANCEL")
.onNegative((dialog, which) -> result.cancel())
.show();
return true;
}
});
答案 1 :(得分:1)
据说使用WebChromeClient
和覆盖方法onJsAlert()
。这是一个示例代码。
WebView wv=new WebView(this);
wv.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message,JsResult result) {
//Required functionality here
return super.onJsAlert(view, url, message, result);
}
这是link以获取更多信息。
答案 2 :(得分:0)
不要覆盖onJsAlert,只需使用:
WebView wv = new WebView(this);
wv.setWebChromeClient(new WebChromeClient());