android :webview 解決遇到的跨域問題
阿新 • • 發佈:2019-01-22
class MyWebViewClient1 extends WebChromeClient {
@Override
public void onProgressChanged(WebView view, int newProgress) {
setTitle("頁面載入中,請稍候..." + newProgress + "%");
System.out.println("進度" + newProgress + "%");
setProgress(newProgress * 100);
if (newProgress == 100) {
setTitle(R.string.app_name);
}
}
@Override
public boolean onJsAlert(WebView view, String url, String message,
JsResult result) {
// 對alert的簡單封裝
new AlertDialog.Builder(CmsTopArticaleDetail.this)
.setTitle("提示")
.setMessage(message)
.setPositiveButton("確定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
System.out.println("測試");
}
}).create().show();
result.confirm(); // 處理來自使用者的確認回覆。
return true;
}
@Override
public boolean onJsConfirm(WebView view, String url, String message,
JsResult result) {
// 對alert的簡單封裝
new AlertDialog.Builder(CmsTopArticaleDetail.this)
.setTitle("提示")
.setMessage(message)
.setPositiveButton("確定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
System.out.println("測試1");
}
}).create().show();
result.confirm(); // 處理來自使用者的確認回覆。
return true;
}
@Override
public boolean onJsPrompt(WebView view, String url, String message,
String defaultValue, JsPromptResult result) {
// 對alert的簡單封裝
new AlertDialog.Builder(CmsTopArticaleDetail.this)
.setTitle("提示" + defaultValue)
.setMessage(message)
.setPositiveButton("確定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
System.out.println("測試");
}
}).create().show();
result.confirm(); // 處理來自使用者的確認回覆。
return true;
}
// return super.onJsPrompt(view, url, message, defaultValue, result);
// }
@Override
public void onRequestFocus(WebView view) {
// TODO Auto-generated method stub
super.onRequestFocus(view);
}
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
// TODO Auto-generated method stub
super.onShowCustomView(view, callback);
}
}