当我的基于Web的应用程序从服务器接收到错误时,我使用以下代码将用户重定向到错误页面。
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webview.loadUrl("file:///android_asset/htmls/error.html");
}
});
但是,如果iframe(而不是网页本身)发生错误,则不会检测到该错误。
附注:我使用fancybox进行某些操作,在某些情况下fancybox打开iframe。
最佳答案
也许将JavascriptInterface添加到您的Web View 中?
JavaScriptInterface interface = new JavaScriptInterface(this);
webview.addJavascriptInterface(JSInterface, "interface");
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void doSomething()
{
}
}
而Javascript方面:
<script type="text/javascript">
function execute()
{
JSInterface.doSomething();
}
</script>
<input type="button" value="Click me!" onclick="execute()" />
关于android - 如何从Android WebView中的iframe捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44672034/