Iframe not loading in webview android

前端 未结 5 442
终归单人心
终归单人心 2021-01-01 00:34

I have a webview. Everything is working fine but when I am opening a page which has iframe, the iframe is not getting visible. Are there any specific settings required?

5条回答
  •  春和景丽
    2021-01-01 00:43

    following hack worked for me for loading iframes in webview.Hope some one still might find it useful

     String webContent="your data to be loaded in webview";
    
    if(webContent.contains("iframe")){
                    Matcher matcher = Pattern.compile("src=\"([^\"]+)\"").matcher(webContent);
                    matcher.find();
                    String src = matcher.group(1);
                    webContent=src;
    
                try {
                    URL myURL = new URL(src);
                    webView.loadUrl(src);
    
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }else {
    
                webView.loadDataWithBaseURL(null, "" + webContent, "text/html", "UTF-8", null);}
    
        }
    }
    

    Also do not forget to add Internet permission in your manifest file.

    
    

提交回复
热议问题