关于webview加载网页出现打不开网页或者空白页面情况的处理
程序员文章站
2022-06-04 14:44:28
...
今天实现webview加载微博网页的功能,开始就是采用了webview.loadurl()方法,直接出现空白页面。当时特别蒙,平时都是直接可以实现效果的,今天居然一直都是空白。后来,在网上查了很多资料。
Android WebView 加载弹出浏览器选择 和 空白页面解决
http://bbs.vpigirl.com/forum.php?mod=viewthread&tid=503&fromuid=2
(出处: 心惊变 回忆的路上,时间变得好慢!)
进行如下设置吧,大多数情况都能解决。
displayWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口,如window.open(),默认为false
displayWebview.getSettings().setJavaScriptEnabled(true);//是否允许执行js,默认为false。设置true时,会提醒可能造成XSS漏洞
displayWebview.getSettings().setSupportZoom(true);//是否可以缩放,默认true
displayWebview.getSettings().setBuiltInZoomControls(true);//是否显示缩放按钮,默认false
displayWebview.getSettings().setUseWideViewPort(true);//设置此属性,可任意比例缩放。大视图模式
displayWebview.getSettings().setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
displayWebview.getSettings().setAppCacheEnabled(true);//是否使用缓存
displayWebview.getSettings().setDomStorageEnabled(true);//DOM Storage
// displayWebview.getSettings().setUserAgentString("User-Agent:Android");//设置用户代理,一般不用
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
缓存不开启的时候,可能会有一些使用了这些存储的网页无法打开。
AppCache和DomStorage介绍见:
http://blog.csdn.net/a345017062/article/details/8703221