Reputation: 551
I was wondering if there was a way to detect blank webpages using the webview.
Actually, this is a college app and so, it would not look appealing if the app loads a blank page and was thinking of using WebView.loadURL("<html><body> <h1>Oops! We have an empty page here</h1></html>")
when I encounter a blank page.
So is there a way to implement this?
Btw. this is a case when the loaded URL webpage is empty and not a rendering issue or whatever it is called!
Upvotes: 3
Views: 3395
Reputation: 2731
There are two possible cases:
Solutions to each case:
WebViewClient
to your WebView
, where you override onReceivedError()
to find out more about the error.WebViewClient
to your WebView
and in onPageFinished()
use javascript to check how many child nodes <body>
has. If it has no child nodes you can show your default html page.To get number of child nodes you can use the javascriptInterface
class like this:
webView.loadUrl("javascript: var count = document.body.childNodes; jsInterface.childCount(count.length);")
Upvotes: 3