WebView頁面顯示不全
阿新 • • 發佈:2019-02-06
最近遇到一個問題,在webview裡面載入https url的時候,如果裡面需要載入http的資源或者重定向的時候,webview會block頁面載入。
錯誤資訊如下:
chromium: [INFO:CONSOLE(0)] "Mixed Content: The page at 'https://iot.onehaier.com/v2/cms/advert.detail.h5?advertId=201612141722070002' was loaded over HTTPS, but requested an insecure
image 'http://onehaiercms.oss-cn-qingdao.aliyuncs.com/2016/12/14/17-21-340871526087485.jpg'. This request has been blocked; the content must be served over HTTPS., source: https://iot.onehaier.com/v2/cms/advert.detail.h5?advertId=201612141722070002 (0)
修改內容如下:
//開啟DOM儲存API settings.setDomStorageEnabled(true); settings.setAllowFileAccess(true); settings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); }