10

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?

4
  • did you enable hardware acceleration ? Commented Jan 19, 2016 at 8:41
  • No.. Is it required? Commented Jan 19, 2016 at 8:41
  • Increased resources required to enable hardware acceleration, so try adding it to activity label or application label in manifest . Commented Jan 19, 2016 at 8:43
  • 3
    Why is iframe dependant on hardware accelaration Commented Jan 19, 2016 at 8:44

6 Answers 6

4

First add Hardware Acceleration and add the following lines to your webView

webView.setWebChromeClient(new WebChromeClient()); 

EDIT 1

It will be hard to identify the problem but try adding WebChromeClient, WebViewClient and also don't forget to enable javascript before loading URL like this

webView= (WebView) findViewById(R.id.webview); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); 

EDIT 2

If you really need to load content of iframe then Try using Jsoup to load html page but you have to find the iframe and fetch the content manually.

Document doc=... Element iframe1 = doc.select("#iframe1").first(); if (iframe1!=null) { Document iframeContent = Jsoup.connect(iframe1.attr("src")).get(); } 

where iframe1 is id of your iframe.

Sign up to request clarification or add additional context in comments.

8 Comments

Why is hardware accelaration necessary?
@mohanmishra as I see many standard browsers and apps uses hardware-accelerated 2D graphics since long before. The main benefit is only extra boost in performance. It is recommended.
This is not working. Is there anything else that i can do??
@mohanmishra is that youtube iframe?
|
2

This maybe a too late answer! I hope it will help someone.

Just try to set up a desktop user agent to your webview

String DESKTOP_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36"; webView.getSettings().setUserAgentString(DESKTOP_USER_AGENT); 

Comments

1

If you modify webview configurations and use loadData function to load iframe, some iframes will not work in webview. So for the solution I have implemented AdvancedWebView library.

https://github.com/delight-im/Android-AdvancedWebView

Use loadHtml(URL) method with this webview and you can pass URL in parameter and you will be able to view iframe in webview.

Comments

1

Only thing that works for me, in Manifest:

android:hardwareAccelerated="true" 

and in your Activity:

webView.getSettings().setDomStorageEnabled(true); 

Comments

0

Can you check if you have

android:hardwareAccelerated="true" 

in your AndroidManifest file, in the <application> tag of that activity.

Comments

0

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, "<style>img{display: inline;height: auto;max-width: 100%;}</style>" + webContent, "text/html", "UTF-8", null);} } } 

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

<uses-permission android:name="android.permission.INTERNET" /> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.