BVB
BVB

Reputation: 5420

Certain website loads blank in WebView, while others work fine - how to fix?

I have a weird issue with my WebView - it loads most, if not all, webpages fine, but http://m.att.com ends up loading white/blank with nothing displayed. Here is my applicable code:

primaryWebView = (WebView) findViewById(R.id.primaryWebView);
primaryWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

primaryWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false; // don't want links to open in an external browser app
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // do some logging
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // do some logging
    }
});

WebSettings settings = primaryWebView.getSettings();
settings.setAllowFileAccess(true);
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

primaryWebView.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) {
        // update progress bar
    }
});

primaryWebView.loadUrl(url);

What's interesting is if I remove settings.setJavaScriptEnabled(true);, then the page loads, but it looks extremely incorrect. The http://m.att.com site loads fine on my desktop computer and in Google Chrome on my test device. What can I do?

Upvotes: 2

Views: 599

Answers (1)

BVB
BVB

Reputation: 5420

I found a solution by trying out WebView-based applications on Google Play. WebView Developer Browser was the first one that was able to work the http://m.att.com page. Thankfully, the app's author provided a github link to the code. I was able to look at his single Activity to find that I have been missing a couple of settings from WebSettings.

The setting that made loading work correctly was the following:

settings.setDomStorageEnabled(true);

Upvotes: 4

Related Questions