日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android js 弹窗,Android WebView 不能弹出alert的对话框

發布時間:2023/12/19 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android js 弹窗,Android WebView 不能弹出alert的对话框 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

加載WebView彈框沒有彈出來,百思不得其解,后來發現是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方法默認返回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

當我們覆蓋父類WebChromeClient的方法onJsAlert,設置為true,也是不行的。那么整個頁面的焦點都在alert這里,這個頁面觸摸將會沒有任何反應。只有返回super.onJsAlert(view,url,message,result)時,才能在需要alert彈框時才獲取焦點,其余的由WebView自己處理。

謝謝閱讀

文章來源: blog.csdn.net,作者:WongKyunban,版權歸原作者所有,如需轉載,請聯系作者。

原文鏈接:blog.csdn.net/weixin_40763897/article/details/88951765

總結

以上是生活随笔為你收集整理的android js 弹窗,Android WebView 不能弹出alert的对话框的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。