android js 弹窗,Android WebView 不能弹出alert的对话框
加載WebView彈框沒有彈出來,百思不得其解,后來發(fā)現(xiàn)是Android WebView會阻止alert對話框彈出。如何才能讓它不阻止呢,解決方法如下:
mWebview.setWebChromeClient(new WebChromeClient(){ @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } });1
2
3
4
5
6
7
問題成功解決!
源碼中WebChromeClient類的onJsAlert方法默認(rèn)返回false:
/** * Tell the client to display a javascript alert dialog. If the client * returns {@code true}, WebView will assume that the client will handle the * dialog. If the client returns {@code false}, it will continue execution. * @param view The WebView that initiated the callback. * @param url The url of the page requesting the dialog. * @param message Message to be displayed in the window. * @param result A JsResult to confirm that the user hit enter. * @return boolean Whether the client will handle the alert dialog. */ public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return false; }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
當(dāng)我們覆蓋父類WebChromeClient的方法onJsAlert,設(shè)置為true,也是不行的。那么整個頁面的焦點都在alert這里,這個頁面觸摸將會沒有任何反應(yīng)。只有返回super.onJsAlert(view,url,message,result)時,才能在需要alert彈框時才獲取焦點,其余的由WebView自己處理。
謝謝閱讀
文章來源: blog.csdn.net,作者:WongKyunban,版權(quán)歸原作者所有,如需轉(zhuǎn)載,請聯(lián)系作者。
原文鏈接:blog.csdn.net/weixin_40763897/article/details/88951765
總結(jié)
以上是生活随笔為你收集整理的android js 弹窗,Android WebView 不能弹出alert的对话框的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ap频段什么意思(AP课程是什么)
- 下一篇: ps怎么做文字效果(PS如何做文字扫描效